vite.config.js加载出错

代码运行后报错:

 __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'D:\javaProject\zmyParkAdmin\package.json' contains "type": "module". To treat it a
s a CommonJS script, rename it to use the '.cjs' file extension.

failed to load config from D:\javaProject\zmyParkAdmin\vite.config.js
error when starting dev server:
ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'D:\javaProject\zmyParkAdmin\package.json' contains "type": "module". To treat it a
s a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///D:/javaProject/zmyParkAdmin/vite.config.js?t=1723429347663:15:25
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
    at async loadConfigFromFile (D:\javaProject\zmyParkAdmin\node_modules\vite\dist\node\chunks\dep-6e2fe41e.js:61925:31)
    at async resolveConfig (D:\javaProject\zmyParkAdmin\node_modules\vite\dist\node\chunks\dep-6e2fe41e.js:61456:28)
    at async createServer (D:\javaProject\zmyParkAdmin\node_modules\vite\dist\node\chunks\dep-6e2fe41e.js:60111:20)
    at async CAC.<anonymous> (D:\javaProject\zmyParkAdmin\node_modules\vite\dist\node\cli.js:688:24)

修改方法:将package.json文件中的 "type": "module"删除

在package.json根节点中添加 "type": "module" 节点,可以将node.js默认支持CommomJS 模块化规范,修改为支持ES6模块语法(node版本大于14.15.1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值