framework icon indicating copy to clipboard operation
framework copied to clipboard

Fail to import .scss async

Open ilyary opened this issue 2 years ago • 3 comments

Environment

  • Operating System: Darwin
  • Node Version: v14.19.3
  • Nuxt Version: 3.0.0-rc.10
  • Nitro Version: 0.5.3
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: app, vite
  • Runtime Modules: -
  • Build Modules: -
"devDependencies": {
    "firebase-tools": "^11.9.0",
    "nuxt": "^3.0.0-rc.10",
    "sass": "^1.54.8",
    "sass-loader": "^13.0.2"
  },
  "dependencies": {
    "@fortawesome/fontawesome-free": "^6.2.0",
    "bootstrap": "^5.2.0"
  }

Reproduction

https://github.com/ilyary/hyve-gtm

Describe the bug

Fails to import like this: import("@/styles/async.scss");

<template>
  <NuxtPage />
</template>

<script>
import "bootstrap/scss/bootstrap.scss";

//import "@/styles/async.scss"; // That works

import("@/styles/xxx.js"); // That works

import("@/styles/async.scss"); // Not working
/*
>npm run generate
...

ℹ Initializing prerenderer

ERROR  Rollup error: Could not resolve './_nuxt/async.744a712b.js' from .nuxt/dist/server/server.mjs                                         nitro 09:45:18


ERROR  Could not resolve './_nuxt/async.744a712b.js' from .nuxt/dist/server/server.mjs                                                             09:45:18

 at error (node_modules/rollup/dist/es/shared/rollup.js:1858:30)
 at ModuleLoader.handleResolveId (node_modules/rollup/dist/es/shared/rollup.js:22357:24)
 at ModuleLoader.resolveDynamicImport (node_modules/rollup/dist/es/shared/rollup.js:22411:120)
 at async node_modules/rollup/dist/es/shared/rollup.js:22306:32
 */
</script>

Additional context

No response

Logs

No response

ilyary avatar Sep 19 '22 16:09 ilyary

What are you trying to do with a dynamic import of CSS?

You may be able to do what you want with:

if (process.client) {
  import("@/styles/async.scss");
}

danielroe avatar Sep 19 '22 20:09 danielroe

What are you trying to do with a dynamic import of CSS?

I'm trying to load heavy fontawesome assets after app bundle is loaded.

"if(process.client)" does the trick, thank you.

The reason I raised this issue is that "import("@/styles/async.scss")" works on origin Vue SSG both client/server but not on Nuxt

ilyary avatar Sep 28 '22 07:09 ilyary