node.js 中默认仅支持 CommonJS 模块化规范
基于 node.js 体验与学习 ES6 的模块化语法,可以按照 如下两个步骤进行配置:
① 确保安装了 v14.15.1 或更高版本的 node.js
② 在 package.json 的根节点中添加 "type": "module" 节点
npm init -y 快速创建package.json文件然后在里面配置 "type": "module"
{
"type": "module",
"name": "node1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}