首页 前端知识 解决:Failed to load PostCSS config: Failed to load PostCSS config

解决:Failed to load PostCSS config: Failed to load PostCSS config

2024-08-30 02:08:11 前端知识 前端哥 123 60 我要收藏

报错信息:

[Failed to load PostCSS config: Failed to load PostCSS config (searchPath: D:/project/vite-vue-project): [Error] Must use import to load ES Module: D:\project\vite-vue-project\postcss.config.ts
require() of ES modules is not supported.
require() of D:\project\vite-vue-project\postcss.config.ts from D:\project\vite-vue-project\node_modules\.store\vite@5.3.3\node_modules\vite\dist\node\chunks\dep-CzJTQ5q7.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 D:\project\vite-vue-project\package.json.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: D:\project\vite-vue-project\postcss.config.ts
require() of ES modules is not supported.
require() of D:\project\vite-vue-project\postcss.config.ts from D:\project\vite-vue-project\node_modules\.store\vite@5.3.3\node_modules\vite\dist\node\chunks\dep-CzJTQ5q7.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 D:\project\vite-vue-project\package.json.

解析:

xxx.js是一个ES模块文件,因为它是一个.ts文件,其最近的父包.json包含“type”:“module”,它将该包范围内的所有.ts文件定义为ES模块。
相反,请更改使用import()所需的代码,或者从D:\project\vite-vue-project\package.json中删除“type”:“module”。

解决方案:

方案1. 找到package.json文件,去掉以下配置
"type": "module",
方案2. 将 postcss.config.js 重命名为 postcss.config.cjs 

但vite5有的可能仍然提示cjs已经过时。

方案3. 将 postcss.config.cjs 重命名为 postcss.config.mts 或 postcss.config.cts 

 

参考:Troubleshooting | Vite (vitejs.dev) 

转载请注明出处或者链接地址:https://www.qianduange.cn//article/17144.html
标签
Vite
评论
发布的文章

npm install 报错解决记录

2024-09-09 00:09:08

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!