我升级了 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/