Reb*_*eca 35 node.js vue.js nuxt.js
我升级了节点并构建了现有文件。
但它没有构建,并且出现了错误。
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.
Run Code Online (Sandbox Code Playgroud)
所以我删除了 package.json 文件中的“类型:模块”。
去掉可以吗?
Afs*_*bbi 57
当 package.json 文件中有 'type: module' 时,您的源代码应该使用import语法。当你没有时,你应该使用require语法。
添加'type': 'module'到package.json启用 ES 6 模块。有关更多信息,请参见此处。
kis*_*ssu 30
如果您使用的是 Node.js v16,而且您应该尽可能使用它,因为它是 LTS,您只需type: module按照此处的说明使用: https: //blog.logrocket.com/es-modules-in-node-today/
如果由于某些原因您仍然使用较低版本的 Node.js,您可以关注 Flavio 的这篇博客文章:https ://flaviocopes.com/how-to-enable-es-modules-nodejs/
并执行以下操作:
"type": "module"您的package.json--experimental-modules启动应用程序时使用,例如:node --experimental-modules app.js或者,如果已经在现代版本的 Node 上,您可以执行其中一项操作:
"type": "module"您的package.json.mjs,最终结果将如下所示node app.mjs| 归档时间: |
|
| 查看次数: |
46199 次 |
| 最近记录: |