我在Nuxt.js中重新安装了node_modules,突然出现了必须使用import加载ES模块:~



当我重新安装node_modules时,我突然被告知缺少ufo和nodefetch。添加它们之后,我运行npm run dev并在浏览器中打开localhost,遇到了这个错误。

这个错误也发生在我在另一台笔记本电脑上克隆这个项目时,我不知道如何修复它

我试图尽可能地自己解决这个问题,但我找不到解决方案,因为堆栈帧在某种程度上是Missing stack frames,而这个错误本身就是库中的一个错误。我不太熟悉策略溢出问题,所以如果你发现任何问题,请告诉我。

错误

Must use import to load ES Module: C:UsersCouDocuments就職関係job_portfolionuxt_mainnode_modules.pnpmnode-fetch@3.2.6node_modulesnode-fetchsrcindex.js require() of ES modules is not supported. require() of C:UsersCouDocuments就職関係job_portfolionuxt_mainnode_modules.pnpmnode-fetch@3.2.6node_modulesnode-fetchsrcindex.js from C:UsersCouDocuments就職関係job_portfolionuxt_mainnode_modules.pnpmvue-server-renderer@2.6.14node_modulesvue-server-rendererbuild.dev.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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:UsersCouDocuments就職関係job_portfolionuxt_mainnode_modules.pnpmnode-fetch@3.2.6node_modulesnode-fetchpackage.json.

堆叠帧

internal/modules/cjs/loader.js:1089:13
Module._extensions..js
internal/modules/cjs/loader.js:937:32
Module.load
internal/modules/cjs/loader.js:778:12
Module._load
internal/modules/cjs/loader.js:961:19
Module.require
internal/modules/cjs/helpers.js:92:18
require
webpack:/external "node-fetch":1:
Object.node-fetch
webpack/bootstrap:25:
__webpack_require__
.nuxt/server.js:1:
Module../.nuxt/server.js
webpack/bootstrap:25:
__webpack_require__

软件包.json

{
"name": "nuxt_main",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint:js": "eslint --ext ".js,.vue" --ignore-path .gitignore .",
"lint:style": "stylelint "**/*.{css,scss,sass,html,vue}" --ignore-path .gitignore",
"lint:prettier": "prettier --check .",
"lint": "npm run lint:js && npm run lint:style && npm run lint:prettier",
"lintfix": "prettier --write --list-different . && npm run lint:js -- --fix && npm run lint:style -- --fix",
"prepare": "husky install",
"test": "jest"
},
"lint-staged": {
"*.{js,vue}": "eslint --cache",
"*.{css,scss,sass,html,vue}": "stylelint",
"*.**": "prettier --check --ignore-unknown"
},
"dependencies": {
"@mdi/js": "^6.7.96",
"@nuxtjs/axios": "^5.13.6",
"core-js": "^3.19.3",
"csv-loader": "^3.0.3",
"csv-parse": "^5.2.0",
"fs": "0.0.1-security",
"node-fetch": "^3.2.6",
"nuxt": "^2.15.8",
"pnpm": "^7.4.0",
"ufo": "^0.8.4",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vuetify": "^2.6.1",
"webpack": "^4.46.0"
},
"devDependencies": {
"@babel/eslint-parser": "^7.16.3",
"@nuxtjs/eslint-config": "^8.0.0",
"@nuxtjs/eslint-module": "^3.0.2",
"@nuxtjs/stylelint-module": "^4.1.0",
"@nuxtjs/vercel-builder": "^0.22.1",
"@nuxtjs/vuetify": "^1.12.3",
"@vue/test-utils": "^1.3.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^27.4.4",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-nuxt": "^3.1.0",
"eslint-plugin-vue": "^8.2.0",
"husky": "^7.0.4",
"jest": "^27.4.4",
"lint-staged": "^12.1.2",
"postcss-html": "^1.3.0",
"prettier": "^2.5.1",
"stylelint": "^14.1.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended-vue": "^1.1.0",
"stylelint-config-standard": "^24.0.0",
"vue-jest": "^3.0.4"
}
}

操作系统:Windows节点:v14.17.4

显然是由于pnpm无法安装所有所需的软件包。运行pnpm安装,然后运行npm安装(或yarn安装)解决了这个问题。

相关内容

  • 没有找到相关文章