解决Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
解决Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension错误。
·
1、问题描述
今天在idea运行vue项目的时候,出现如下图的错误,

2、解决办法
在pakeage.json文件中添加"type": "module"

如果在pakeage.json文件中添加"type": "module"还是报错,那么
就改成"type": "commonjs"试试。
属性解释
在 package.json 中配置 type 字段可以指定 Node.js 项目中 JavaScript 文件的模块系统:
-
"type": "commonjs":这是默认值。它表示你的项目使用 CommonJS 模块系统,这是 Node.js 默认的模块格式。CommonJS 使用 require 来导入模块和 module.exports 来导出模块。 -
"type": "module":它表示你的项目使用 ES 模块系统。ES 模块使用 import 和 export 来处理模块。这种模块系统是现代 JavaScript 标准的一部分,允许使用更现代的模块语法。
选择 type 取决于你希望使用哪种模块系统,并且它会影响如何解析项目中的 .js 文件。
更多推荐



所有评论(0)