vite-ssg: ERR_UNKNOWN_FILE_EXTENSION - Problem with import css/scss from pnpm/node_modules
I have some components with styles from swiper. Now when I tried to build it to production with css or scss I have error: ERR_UNKNOWN_FILE_EXTENSION
problematic code in vue script tags:
import 'swiper/scss'
import 'swiper/scss/scrollbar'
issue when build to prod:
[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".scss" for C:\test\node_modules\.pnpm\swiper@7.3.3\node_modules\swiper\swiper.scss
at new NodeError (node:internal/errors:371:5)
at Object.file: (node:internal/modules/esm/get_format:72:15)
at defaultGetFormat (node:internal/modules/esm/get_format:85:38)
at defaultLoad (node:internal/modules/esm/load:22:14)
at ESMLoader.load (node:internal/modules/esm/loader:353:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:274:58)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:291:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:255:34)
at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:81:21) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Node.js v17.2.0
ELIFECYCLE Command failed with exit code 1.
the same with css:
[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".css" for C:\test\node_modules\.pnpm\swiper@7.3.3\node_modules\swiper\swiper.min.css
at new NodeError (node:internal/errors:371:5)
at Object.file: (node:internal/modules/esm/get_format:72:15)
at defaultGetFormat (node:internal/modules/esm/get_format:85:38)
at defaultLoad (node:internal/modules/esm/load:22:14)
at ESMLoader.load (node:internal/modules/esm/loader:353:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:274:58)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:291:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:255:34)
at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:81:21) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Node.js v17.2.0
ELIFECYCLE Command failed with exit code 1.
I used Vitesse starter template, with development everything working like a charm.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 14
- Comments: 21
The solution with vite 3 is to set the package to ssr.noExternal For example:
same issue
“vite”: “^2.7.10”, “vite-ssg”: “^0.17.5” “swiper”: “^7.4.1”,
Same issue here but with Element Plus
Did you find a solution to that ?
Probably it’s an issue with Vite’s import analysis. I made a plugin that removes
swiper/css
imports from the SSR bundle to allowvite-ssg
to generate SSR pages successfully.I’m getting the same error again, this time with Vuetify 3 beta.
I was trying to import:
Error message:
I later tried replacing it by directly importing the CSS file but the issue still exists, this time with a different CSS file in the Vuetify package (
\node_modules\vuetify\lib\components\VCode\VCode.css
).Update vite@^3.0.0-alpha.9, it works well.
@zouhangwithsweet does not work for me
I also using Swiper and notice if I use @sibbng 's solution, Swiper stops to work on
dev
.