《Vite 报错》ReferenceError: module is not defined in ES module scope
trip): [ReferenceError] module is not defined in ES module scope
解决方案
postcss.config.js
要改为 postcss.config.cjs
,也就是 .cjs
后缀。
原因解析
原因解析
- 下图提示,
packages.json
中的属性type
设置为module
。所有*.js
文件现在都被解释为*.js
; - 但
Vite
有说明, postcss配置文件暂不支持 ESM 语法,所以冲突了; - 改为`` .cjs 后缀,继续以
CommonJS
方式加载此文件即可; - 想进一步了解 Vite 对 CommonJS 的 说明在此;
参考链接1