chai TypeError:为 express.js 后端运行“npm start”时,util.addProperty 不是函数

问题描述 投票:0回答:0

我知道的方法都试过了,还是无法解决下面的问题,还想请教大家。非常感谢您。

应用程序运行良好直到昨天,然后我添加了一些功能和测试用例并且我没有添加任何新的依赖项(我已经通过检查 Github 上的提交历史确认)。测试运行良好,然后我运行

npm run dev
npm start 
,我有以下问题报告来自 chai 的打字错误(我仍然可以通过
npm run test
运行测试)。

我尝试过的东西:

  1. 在 Google 上搜索 'TypeError: util.addProperty is not a function',没有任何内容
  2. 按照承诺重新安装 chai 和 chai
  3. 删除 node_modules 并通过运行重新安装所有依赖项
    npm i
  4. 将节点从 18.7.0 升级到 18.16.0

我现在该怎么办?有什么线索吗?

~~/node_modules/chai/lib/chai/assertion.js:94
    util.addProperty(this.prototype, name, fn);
         ^

TypeError: util.addProperty is not a function
    at Assertion.addProperty (/Users/jingjiejiang/Documents/My_Project/WeChatBot/WechatBot_Server/node_modules/chai/lib/chai/assertion.js:94:10)
    at /Users/jingjiejiang/Documents/My_Project/WeChatBot/WechatBot_Server/node_modules/chai/lib/chai/core/assertions.js:48:15
    at Array.forEach (<anonymous>)
    at module.exports (/Users/jingjiejiang/Documents/My_Project/WeChatBot/WechatBot_Server/node_modules/chai/lib/chai/core/assertions.js:47:46)
    at exports.use (/Users/jingjiejiang/Documents/My_Project/WeChatBot/WechatBot_Server/node_modules/chai/lib/chai.js:39:5)
    at Object.<anonymous> (/Users/jingjiejiang/Documents/My_Project/WeChatBot/WechatBot_Server/node_modules/chai/lib/chai.js:71:9)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)

Node.js v18.16.0

我的包.json:

 "scripts": {
    "start": "node ./bin/www.js",
    "dev": "NODE_ENV=dev nodemon ./bin/www.js",
    "debug": "NODE_ENV=dev node --inspect ./bin/www.js",
    "test": "NODE_ENV=test mocha --recursive --exit --timeout 20000",
    "test:unit": "NODE_ENV=test mocha test/unit --recursive --exit --timeout 20000",
    "test:integration": "NODE_ENV=test mocha test/integration --recursive --exit --timeout 20000"
  },
  "dependencies": {
    "app-root-path": "^3.1.0",
    "axios": "^1.3.5",
    "bcrypt": "^5.1.0",
    "chatgpt": "^5.1.3",
    "cookie-parser": "~1.4.4",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "debug": "~2.6.9",
    "dotenv": "^16.0.3",
    "express": "~4.16.1",
    "handlebars": "^4.7.7",
    "hirestime": "^7.0.3",
    "http-errors": "~1.6.3",
    "ioredis": "^5.3.2",
    "jade": "~1.11.0",
    "jsonwebtoken": "^9.0.0",
    "lodash": "^4.17.21",
    "mint-filter": "^4.0.2",
    "mongoose": "^7.0.0",
    "morgan": "~1.9.1",
    "nodemailer": "^6.9.1",
    "nodemon": "^2.0.21",
    "openai": "^3.2.1",
    "path": "^0.12.7",
    "readline": "^1.3.0",
    "redis": "^4.6.4",
    "redlock": "^5.0.0-beta.2",
    "remark": "^14.0.2",
    "strip-markdown": "^5.0.0",
    "supertest": "^6.3.3",
    "swagger-ui-express": "^4.6.2",
    "winston": "^3.8.2",
    "winston-mongodb": "^5.1.1"
  },
  "devDependencies": {
    "chai": "^4.3.7",
    "chai-as-promised": "^7.1.1",
    "eslint": "^8.34.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-jsx-a11y": "^6.7.1",
    "eslint-plugin-react": "^7.32.2",
    "eslint-plugin-react-hooks": "^4.6.0"
  }
node.js express chai
© www.soinside.com 2019 - 2024. All rights reserved.