使用 npm-peer-dependencies 安装依赖项

Installing dependencies with npm-peer-dependencies

我正在尝试使用 npm install

为小项目 运行ning Angular 11 安装所需的 node_modules

我的目标是让项目在从 GitHub 下载后在本地运行。我已经安装了最新版本的 Angular CLI。 在 运行 安装命令后,我尝试了 npm start

我期待在 运行 安装和启动命令后能够在本地 运行 项目。 然而,我在 运行 安装命令后得到的实际结果是以下错误列表:

> ng serve

An unhandled exception occurred: Cannot find module '@angular/compiler'
Require stack:

\node_modules\@angular\compiler-cli\index.js
\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js
\node_modules\@ngtools\webpack\src\index.js
\node_modules\@angular-devkit\build-angular\src\webpack\configs\typescript.js
\node_modules\@angular-devkit\build-angular\src\webpack\configs\index.js
\node_modules\@angular-devkit\build-angular\src\browser\index.js
\node_modules\@angular-devkit\build-angular\src\dev-server\index.js
\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
\node_modules\@angular-devkit\architect\node\index.js
\node_modules\@angular\cli\models\architect-command.js
\node_modules\@angular\cli\commands\serve-impl.js
\node_modules\@angular-devkit\schematics\tools\export-ref.js
\node_modules\@angular-devkit\schematics\tools\index.js
\node_modules\@angular\cli\utilities\json-schema.js
\node_modules\@angular\cli\models\command-runner.js
\node_modules\@angular\cli\lib\cli\index.js
\node_modules\@angular\cli\lib\init.js
\node_modules\@angular\cli\bin\ng

See "angular-errors.log" for further details.

npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file C:\WINDOWS\system32\cmd.exe
npm ERR! errno ENOENT
npm ERR! `ng serve`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @0.0.16 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

问题是这个Angular项目也有对等依赖。我安装了 npm-install-peers 包,但似乎只是 运行ning npm install 之后不会安装所需的对等依赖项。 接下来我应该怎么做才能在本地安装这个 Angular 项目?

您遇到的问题可能是因为 angular cli 或 npm-peer-dependencies 未在您的计算机上全局安装。 您应该采取的步骤是确保它们已全局安装。 要在全球范围内安装软件包,您需要 运行 npm install -g <package_name> npm docs link

对于 angular cli,你应该 运行 npm i -g @angular/cli@11.2.15npm install -g npm-peer-dependencies。 然后 运行 npm start.