node.js - 为什么 package.json 文件中有 'type: module'?

标签 node.js vue.js nuxt.js

我升级了 Node 并构建了现有文件。

但它没有构建,并且出现错误。

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:                          │
   │   ~~/nuxt.config.js                                      │
   │   require() of ES modules is not supported.                                            │
   │   require() of ~~/nuxt.config.js from                    │
   │   ~~/config.js is an ES   │
   │   module file as it is a .js file whose nearest parent package.json contains "type":   │
   │   "module" which defines all .js files in that package scope as ES modules.            │
   │   Instead rename nuxt.config.js to end in .cjs, change the requiring code to use       │
   │   import(), or remove "type": "module" from                                            │
   │   ~~/package.json.  

所以我在 package.json 文件中删除了 'type: module' 。

删除它好吗?

最佳答案

当你有 "type": "module"package.json文件,您的源代码应使用 import句法。当你没有时,你应该使用require句法。
添加 "type": "module"package.json启用 ES 6 模块。如需更多信息,请参阅 here .

关于node.js - 为什么 package.json 文件中有 'type: module'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61401475/

相关文章:

nuxt.js - 如何通过cypress拦截服务器端api调用

javascript - NodeJS 与 Child_Process - 如何转义我的命令

node.js - 在 Ubuntu 14.04 上安装最新版本的 npm(值得信赖)

vue.js - Vue3 路由器 + 转换警告

javascript - 尝试从 Javascript 中的键获取对象值

javascript - Vue 中的动态条件轮播项目选择

javascript - Express.js : how export an asynchronous result of a promise within my module

node.js - 在某些情况下,我可以永远阻止重新启动我的 Node 脚本吗?

javascript - 带有 webpack require() 的 Vue.js 动态图像 src 不工作

nuxt.js - Nuxt中如何给一组路由添加中间件