我刚刚使用 nvm 更新了 Node 和 npm。当我启动 Node 服务器时,出现此错误。我尝试了不同的解决方案。此类问题已经存在于堆栈溢出中,但这些问题都不适合我。所以我尝试了这些东西但没有用。
1.删除 Node 模块并使用 npm install 安装 Node 模块。
2.更新babel-cli版本。
3.降级node和nvm。
4.npm i 平衡匹配。
5.npm i -g 平衡匹配。
6.npm i 平衡匹配 --save。
我正在添加我的 package.json
{
"name": "******",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon express-server.js --exec babel-node",
"build": "babel ./ -d dist",
"serve": "node dist/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"bluebird": "^3.5.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-es6-template-engine": "^2.0.3",
"express-session": "^1.15.6",
"handlebars": "^4.0.11",
"helmet": "^3.13.0",
"html": "^1.0.0",
"instamojo-nodejs": "0.0.5",
"jsonwebtoken": "^8.2.2",
"lodash": "^4.17.10",
"moment": "^2.22.2",
"mongoose": "^5.1.3",
"mongoose-unique-validator": "^2.0.1",
"multer": "^1.3.0",
"mysql": "^2.15.0",
"node-fetch": "^2.1.2",
"node-schedule": "^1.3.0",
"node-xlsx": "^0.12.1",
"nodemailer": "^4.6.8",
"passport": "^0.4.0",
"passport-google-oauth20": "^1.0.0",
"passport-local": "^1.0.0",
"request": "^2.88.0",
"request-ip": "^2.0.2",
"sanitize-html": "^1.18.2",
"utf8": "^3.0.0",
"validator": "^10.2.0",
"xlsx2json": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"nodemon": "^1.17.5"
}
}
在控制台中它显示如下。 console error
我只为了解决这个问题就浪费了12个小时的时间。
最佳答案
我通过在根文件夹中使用 npm installbalanced-match 安装balanced-match解决了这个问题。我不知道为什么它采用根文件夹 Node 模块。在控制台错误中,明确给出了路径,但我没有意识到。如果有人解释为什么它采用根 Node 模块,这对我会有帮助。
关于node.js - NPM : Error: Cannot find module 'balanced-match' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53446932/