node.js - NPM : Error: Cannot find module 'balanced-match'

标签 node.js npm

我刚刚使用 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/

相关文章:

javascript - npmjs 中是否存在 "Export as war"包?

angular - 为什么 Yarn 无法安装 Angular 2 的作用域包(例如 @angular/common)?

javascript - Promise.resolve 是异步函数吗?

node.js - 如何使用请求将文件从 Node 发送到 Amazon S3?

javascript - React ref 不工作不变违规 : addComponentAsRefTo

node.js - NodeJS、NPM 和 package.json 依赖项

javascript - 拦截控制台日志到文件Nodejs

javascript - 使用 json 和 jsPDF 生成发票 PDF 或帐单 PDF

node.js - 为什么 req.session 在一个路由中设置,而在另一路由调用中不可用?

javascript - 中断 while() 并优雅地完成 Node.js