【问题标题】:How to fix : cannot find Module error in while running the npm run build command如何修复:运行 npm run build 命令时找不到模块错误
【发布时间】:2023-02-15 14:40:53
【问题描述】:

在我的应用程序中,npm run build 命令抛出一个模块未找到错误,如下所示:

npm WARN npm npm does not support Node.js v16.17.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/

> @coreui/lutosa-obs@0.0.1 build C:\Users\Administrator\OneDrive\Documents\OSB-Frontend-production\Lutosa_front-end
> ng build --prod --aot --build-optimizer --common-chunk --vendor-chunk --optimization --progress

'find_dp0' is not recognized as an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:959
  throw err;
  ^

Error: Cannot find module 'C:\@angular\cli\bin\ng.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
}

我不知道我的 npm 包有什么问题。请帮我解决这个问题。

我还附上了我的 package.json 文件。我想知道在我的应用程序中使用 npm run build 错误之前我需要安装哪些包。

  • Package.json 文件:
{
  "name": "@coreui/lutosa-obs",
  "version": "0.00.1",
  "description": "Lutosa OBS Portal",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "postinstall": "ngcc --properties es2015 browser module main --first-only",
    "start": "ng serve",
    "build": "ng build --prod --aot --build-optimizer --common-chunk --vendor-chunk --optimization --progress",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prettier": "prettier --write \"{,!(node_modules|dist|build|coverage)/**/}*.{js,jsx,ts,json}\"",
    "pre-commit": "npm run lint && npm run prettier",
    "extract-i18n": "ngx-translate-extract --input ./src --output ./src/assets/i18n/{en,nl,fr,es,it,de}.json --format namespaced-json --sort"
  },
  "private": true,
  "husky": {
    "hooks": {
      "pre-commit": "npm run pre-commit"
    }
  },
  "dependencies": {
    "@angular/animations": "^11.1.0",
    "@angular/cdk": "^11.1.0",
    "@angular/common": "^11.1.0",
    "@angular/compiler": "^11.1.0",
    "@angular/core": "^11.1.0",
    "@angular/forms": "^11.1.0",
    "@angular/localize": "^11.1.0",
    "@angular/platform-browser": "^11.1.0",
    "@angular/platform-browser-dynamic": "^11.1.0",
    "@angular/router": "^11.1.0",
    "@coreui/angular": "~2.11.1",
    "@coreui/coreui": "^2.1.16",
    "@coreui/coreui-plugin-chartjs-custom-tooltips": "^1.3.1",
    "@coreui/icons": "^2.0.0-rc.0",
    "@coreui/icons-angular": "1.0.0-alpha.3",
    "@fortawesome/angular-fontawesome": "^0.8.2",
    "@fortawesome/fontawesome-svg-core": "^1.2.34",
    "@fortawesome/free-brands-svg-icons": "^5.15.2",
    "@fortawesome/free-regular-svg-icons": "^5.15.2",
    "@fortawesome/free-solid-svg-icons": "^5.15.2",
    "@ng-select/ng-select": "^6.1.0",
    "@ngrx/store": "^11.0.1",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "@rxweb/reactive-form-validators": "^2.1.2",
    "@uiowa/digit-only": "^2.2.3",
    "ag-grid-angular": "^25.1.0",
    "ag-grid-community": "^25.1.0",
    "bootstrap": "^4.6.0",
    "bs-stepper": "^1.7.0",
    "chart.js": "^2.9.4",
    "classlist.js": "^1.1.20150312",
    "cookieconsent": "^3.1.1",
    "core-js": "^3.8.3",
    "lodash": "^4.17.21",
    "messageformat": "^2.3.0",
    "module_name": "^1.0.0",
    "moment": "^2.29.1",
    "moment-timezone": "^0.5.33",
    "ng-lazyload-image": "9.1.0",
    "ngrx-store-localstorage": "^11.0.0",
    "ngx-avatar": "^4.1.0",
    "ngx-bootstrap": "^6.2.0",
    "ngx-cookieconsent": "^2.2.3",
    "ngx-editor": "^9.0.2",
    "ngx-perfect-scrollbar": "^10.1.0",
    "ngx-toastr": "^13.2.1",
    "ngx-translate-cache": "^9.0.2",
    "ngx-translate-messageformat-compiler": "^4.9.0",
    "primeflex": "^2.0.0",
    "primeicons": "^4.1.0",
    "primeng": "^11.2.3",
    "rxjs": "^6.6.3",
    "simple-line-icons": "^2.5.5",
    "ts-helpers": "^1.1.2",
    "tslib": "^2.0.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1101.1",
    "@angular/cli": "^14.2.2",
    "@angular/compiler-cli": "^11.1.0",
    "@angular/language-service": "^11.1.0",
    "@biesbjerg/ngx-translate-extract": "^7.0.3",
    "@types/jasmine": "^3.6.3",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^14.14.22",
    "codelyzer": "^6.0.0",
    "husky": "^5.1.2",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.2.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "prettier": "^2.2.1",
    "protractor": "~7.0.0",
    "ts-node": "^8.10.2",
    "tslint": "~6.1.0",
    "typescript": "~4.0.5"
  },
  "engines": {
    "node": ">= 10.13",
    "npm": ">= 6"
  }
}

【问题讨论】:

  • 检查你的 npm 版本。您可能需要升级版本

标签: node.js angular npm npm-install npm-run


【解决方案1】:

首先,我希望你删除“node module”文件夹和“package-lock.json”文件,然后

您可以在 NVM 的帮助下更改节点版本

nvm install 14
nvm use 14

现在您可以检查节点版本

node --version 

然后你可以做

npm i -force

你的模块将被安装

【讨论】:

  • 我不明白为什么没有 --force 就没有安装它们。这样做了...
【解决方案2】:

也许你只是忘了跑步npm 我首先,至少对我而言。

【讨论】:

    【解决方案3】:

    初始化 npm 错误可以通过检查和尝试一些事情来解决。

    1. 您拥有最新版本的 npm 和上述软件包
    2. 尝试使用npm i -f 强制安装 npm
    3. 尝试使用npm run audit审计npm modules并修复

      或者

      只需删除所有 npm 文件并重新安装它们,然后尝试相同的操作。

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 1970-01-01
      • 2021-09-11
      • 2021-03-03
      • 2022-01-25
      • 2021-09-16
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      相关资源
      最近更新 更多