Angular 15:error发生意外错误:“在c:path\\node_module中找不到要链接的webpack-dev-server副本

unguejic  于 2023-06-06  发布在  Webpack
关注(0)|答案(1)|浏览(152)

Angular 15:error发生意外错误:“在c:path\node_module中找不到要链接的webpack-dev-server副本。我试图使用yarn安装包依赖项,它出现了上面的错误。项目安装和构建前一段时间很好,然而,最近它要求webpack-dev-server,我没有在其他Angular项目中显式配置它,想知道它做什么,为什么现在问我。提前感谢您的帮助和意见。
package.json

{
  "name": "@website",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint",
    "lint:staged": "lint-staged",
    "lint:styles": "./node_modules/.bin/stylelint src/**/*.scss --fix",
    "e2e": "ng e2e",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run",
    "cypress:component": "cypress open --component",
    "format": "yarn prettier --write .",
    "prepare": "cd ../.. && husky install src/website-remote-iam/.husky"
  },
  "lint-staged": {
    "*.{js, ts}": [
      "eslint --quiet --fix"
    ],
    "*.{json, md, html, js, ts}": [
      "prettier --write"
    ],
    "*.scss": [
      "stylelint src/**/*.scss"
    ]
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "15.0.2",
    "@angular/common": "15.0.2",
    "@angular/compiler": "15.0.2",
    "@angular/core": "15.0.2",
    "@angular/forms": "15.0.2",
    "@angular/platform-browser": "15.0.2",
    "@angular/platform-browser-dynamic": "15.0.2",
    "@angular/router": "15.0.2",
    "@ngxs/store": "3.7.6",
    "rxjs": "7.6.0",
    "tslib": "2.4.1",
    "zone.js": "0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "15.0.2",
    "@angular-eslint/builder": "15.1.0",
    "@angular-eslint/eslint-plugin": "15.1.0",
    "@angular-eslint/eslint-plugin-template": "15.1.0",
    "@angular-eslint/schematics": "15.1.0",
    "@angular-eslint/template-parser": "15.1.0",
    "@angular/cli": "15.0.2",
    "@angular/compiler-cli": "15.0.2",
    "@cypress/schematic": "2.4.0",
    "@types/jasmine": "4.3.1",
    "@types/node": "18.11.5",
    "@typescript-eslint/eslint-plugin": "5.45.1",
    "@typescript-eslint/parser": "5.45.1",
    "cypress": "11.2.0",
    "eslint": "8.18.0",
    "eslint-config-prettier": "8.5.0",
    "eslint-plugin-cypress": "^2.12.1",
    "eslint-plugin-prettier": "4.2.1",
    "husky": "8.0.2",
    "jasmine-core": "4.5.0",
    "karma": "6.4.0",
    "karma-chrome-launcher": "3.1.0",
    "karma-coverage": "2.2.0",
    "karma-jasmine": "5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "lint-staged": "13.0.3",
    "ngx-build-plus": "15.0.0",
    "prettier": "2.8.0",
    "prettier-eslint": "15.0.1",
    "pretty-quick": "3.1.3",
    "serverless-localstack": "1.0.0",
    "stylelint": "14.15.0",
    "stylelint-config-prettier-scss": "0.0.1",
    "stylelint-config-standard-scss": "6.1.0",
    "typescript": "4.8.4"
  }
}

已安装的npm install --save-dev webpack-dev-server also needed install npm install --save-dev webpack-dev-middleware webpack-hot-middleware它绕过了此错误,但没有构建,说明CLI版本不匹配

2izufjch

2izufjch1#

您遇到的错误消息表明项目的依赖项中缺少webpack-dev-server包,或者在指定的路径中找不到该包。
webpack-dev-server包是一个开发服务器,通常与webpack一起使用,以提供实时重新加载和其他与开发相关的功能。它允许您在开发期间在本地运行Angular应用程序,并提供一个开发服务器,可以在进行更改时自动重新加载应用程序。
要解决此问题,您可以尝试以下步骤:
1.确保webpack-dev-server作为依赖项包含在项目的package.json文件中。您可以检查它是否存在于"dependencies""devDependencies"部分。如果缺少,可以通过运行以下命令添加:

yarn add webpack-dev-server --dev

1.如果package.json中已经存在该软件包,您可以尝试删除node_modules文件夹,然后通过运行以下命令重新安装所有依赖项:

yarn install

1.如果问题仍然存在,可能是由于您的yarn缓存存在问题。您可以尝试通过运行以下命令来清除yarn缓存:

yarn cache clean

1.如果上述解决方案都不起作用,则可能是项目的配置文件或依赖项存在问题。在这种情况下,您可能需要提供有关项目设置的更多信息,例如angular.json文件或webpack.config.js文件,以进一步诊断问题。
值得注意的是,webpack-dev-server包通常用于Angular项目,特别是那些使用Angular CLI的项目。如果您的项目之前没有显式配置webpack-dev-server,则很可能是Angular CLI或项目的某个依赖项自动包含了它。
希望能帮上忙。如果它解决了您的问题,请考虑接受,以便其他人可以获得帮助。

相关问题