我升级了节点并构建了现有文件。
但是它没有构建成功,出现了错误。
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'。
删除它是否可以?
package.json
中省略了type
字段,其效果与将其设置为CJS相同。(规范中指出:“如果最近的父级package.json
缺少type
字段或包含type
:commonjs
,则.js
文件将被视为CommonJS格式。如果到达卷根并且找不到package.json
,Node.js会使用默认值,即一个没有type
字段的package.json
。) - jacobq