You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vite supports typescript based config files for things like postcss using ts-node to compile to js. Unfortunately this only works for CommonJS based projects. Native ESM based projects using vite (such as that generated by the vue-ts template where "type": "module" is set in package.json) produce an error when a postcss.config.ts file is present.
[plugin:vite:css] Failed to load PostCSS config (searchPath: /home/projects/vitejs-vite-dbn5r1): [Error] Must use import to load ES Module: /home/projects/vitejs-vite-dbn5r1/postcss.config.ts
require() of ES modules is not supported.
require() of /home/projects/vitejs-vite-dbn5r1/postcss.config.ts from /home/projects/vitejs-vite-dbn5r1/node_modules/vite/dist/node/chunks/dep-b6b8dfbf.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from /home/projects/vitejs-vite-dbn5r1/package.json.
Error: Must use import to load ES Module: /home/projects/vitejs-vite-dbn5r1/postcss.config.ts
require() of ES modules is not supported.
require() of /home/projects/vitejs-vite-dbn5r1/postcss.config.ts from /home/projects/vitejs-vite-dbn5r1/node_modules/vite/dist/node/chunks/dep-b6b8dfbf.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from /home/projects/vitejs-vite-dbn5r1/package.json.
at createErrRequireEsm (/home/projects/vitejs-vite-dbn5r1/node_modules/ts-node/dist-raw/node-internal-errors.js:46:15)
at assertScriptCanLoadAsCJSImpl (/home/projects/vitejs-vite-dbn5r1/node_modules/ts-node/dist-raw/node-internal-modules-cjs-loader.js:584:11)
at registerExtension/require.extensions[ext] (/home/projects/vitejs-vite-dbn5r1/node_modules/ts-node/src/index.ts:1610:29)
at [object Object]
at [object Object]
at [object Object]
at [object Object]
at [object Object]
at [object Object]
at [object Object]
/home/projects/vitejs-vite-dbn5r1/src/App.vue
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
I don't think there's anything we can do. It's an upstream issue at postcss/postcss-load-config#239. postcss-load-config should use import() in this case if the config is compiled to ESM.
Describe the bug
Vite supports typescript based config files for things like postcss using ts-node to compile to js. Unfortunately this only works for CommonJS based projects. Native ESM based projects using vite (such as that generated by the vue-ts template where
"type": "module"
is set in package.json) produce an error when apostcss.config.ts
file is present.Reproduction
https://stackblitz.com/edit/vitejs-vite-dbn5r1?file=postcss.config.ts
Steps to reproduce
Create new vue-ts project with https://vite.new/vue-ts or locally with
npm create vite@latest ts-postcss-config -- --template vue-ts
Install ts-node as required by vite to load typescript based config files.
Adding
postcss.config.ts
to the root with the contents:System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: