(节点:9374)警告:要加载ES模块,请设置"type": [英] (node:9374) Warning: To load an ES module, set "type": "module"

查看:23
本文介绍了(节点:9374)警告:要加载ES模块,请设置"type":的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天才开始学习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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆