code runner (node:5600) Warning: To load an ES module, set "type": "module"

253 阅读1分钟
原因:
使用code runner调试js时,使用ES6的import export,报错(node:5600) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

文件1:

image.png

文件2:

1.导入文件1,报错(node:5600) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

image.png

解决:
1.使用npm init 生成一个package.json
2.package.json中添加"type": "module",如下图所示:

image.png

运行成功:

image.png