(节点:9374)警告:要加载ES模块,请设置"type": [英] (node:9374) Warning: To load an ES module, set "type": "module"
问题描述
我今天才开始学习React.如何摆脱Visual Studio终端中控制台上的错误消息.
I just started to learn React today. How do I get rid of that error message on my Console in the Terminal in Visual Studio.
(node: 9374)Warning: To load an ES module,
set "type": "module" in the package.json or use the .mjs extension.
/Users/nishihaider/workspace-ui/react-todo-app/src/App.js:1
import React from "react";
import "./App.css";
function App() {
<>
return (
<h1>ToDo</h1>
);
</>
}
export default App;
推荐答案
首先,安装最新版本的Node.js.它具有最新和最强大的功能.
First, install the latest version of Node.js. It has the latest and greatest features.
第二,在 package.json
文件中添加"type":"module"
行.
Second, add the "type": "module"
line in your package.json
file.
{
"type": "module"
}
第三,在调用nodejs时使用-experimental-modules
标志:
Third, use the --experimental-modules
flag when invoking nodejs:
node --experimental-modules app.js
你应该很好!
一种替代方法是避免添加"type":"module".您的package.json文件中的一行,然后将app.js文件重命名为app.mjs.
An alternative is to avoid adding the "type": "module" line in your package.json file and instead rename your app.js file to app.mjs.
请注意,现在 require()
语法将停止工作.
这篇关于(节点:9374)警告:要加载ES模块,请设置"type":的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!