NodeJS 已安装的npm包的MODULE_NOT_FOUND错误

qaxu7uf2  于 2023-06-29  发布在  Node.js
关注(0)|答案(1)|浏览(291)

当我使用npm-run-all运行命令时,我看到一个错误:

Error: Cannot find module 'define-properties'
Require stack:
- /local/node/src/Widgets/node_modules/string.prototype.padend/index.js
- /local/node/src/Widgets/node_modules/npm-run-all/lib/run-task.js
- /local/node/src/Widgets/node_modules/npm-run-all/lib/run-tasks.js
- /local/node/src/Widgets/node_modules/npm-run-all/lib/index.js
- /local/node/src/Widgets/node_modules/npm-run-all/bin/run-s/main.js
- /local/node/src/Widgets/node_modules/npm-run-all/bin/common/bootstrap.js
- /local/node/src/Widgets/node_modules/npm-run-all/bin/run-s/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
    at Function.Module._load (node:internal/modules/cjs/loader:871:27)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18)

即使我已经通过运行npm install define-properties --save安装了模块

"@babel/core": "^7.22.5",
"@babel/plugin-syntax-typescript": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@types/enzyme": "^3.10.13",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/react": "^18.2.12",
"@types/react-dom": "^18.2.5",
"@types/testing-library__jest-dom": "^5.14.6",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"babel-loader": "^9.1.2",
"balanced-match": "^2.0.0",
"classnames": "^2.3.2",
"css-loader": "^6.8.1",
"define-properties": "^1.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"read-pkg": "^8.0.0",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^4.9.5",
"whatwg-fetch": "^3.6.2"

脚本如下所示:

"scripts": {
    "check-prettier": "npx prettier --check .",
    "check-ts": "run-s tsc-clean tsc-build tsc-clean",
    "clean": "rm -rf dist && rm -rf node_modules",
    "concurrent-tasks-release": "run-p clean check-prettier check-ts",
    "build": "tsc",
    "build-farm:clean:npm": "rm -fr node_modules",
    "build-farm:clean:workspace": "npm run clean-workspace",
    "build-farm:clean:dev-server": "rm -fr ./dev-server",
    "build-farm:clean:tests": "find ./src -name __tests__ -type d -print0  | xargs -0 rm -rf",
    "release": "run-s concurrent-tasks-release test",
    "tsc-clean": "mkdir -p ./build/private/tmp/check-ts-build && rm -rf ./build/private/tmp/check-ts-build",
    "tsc-build": "tsc --build ./tsconfig.json",
    "test": "npm run test:unit",
    "test:unit": "jest -c ./jest/unit/jest.config.js --runInBand",
  },

有办法解决吗?我还删除了node_modules文件夹,以防缓存问题。

jhdbpxl9

jhdbpxl91#

npm-run-all不喜欢npx see this打开issue
这样做:
1.安装:
npm install npm-run-all
1.将脚本中的npx行替换为:

"scripts": 
     {
     "check-prettier": "npm-run-all prettier --check .",
    },

相关问题