在 netlify 上部署 Angular 应用程序时遇到问题

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

我在将 Angular 应用程序部署到 netlify 时遇到问题,该应用程序在我的本地主机上运行良好,但是当我部署时出现以下错误 有人可以帮忙吗

9:41:28 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
9:41:29 PM: npm ERR! code ERESOLVE
9:41:29 PM: npm ERR! ERESOLVE could not resolve
9:41:29 PM: npm ERR!
9:41:29 PM: npm ERR! While resolving: @angular/[email protected]
9:41:29 PM: npm ERR! Found: @angular/[email protected]
9:41:29 PM: npm ERR! node_modules/@angular/compiler
9:41:29 PM: npm ERR!   @angular/compiler@"^14.0.2" from the root project
9:41:29 PM: npm ERR!   peer @angular/compiler@"14.0.3" from @angular/[email protected]
9:41:29 PM: npm ERR!   node_modules/@angular/platform-browser-dynamic
9:41:29 PM: npm ERR!     @angular/platform-browser-dynamic@"^14.0.2" from the root project
9:41:29 PM: npm ERR!
9:41:29 PM: npm ERR! Could not resolve dependency:
9:41:29 PM: npm ERR! peer @angular/compiler@"14.2.6" from @angular/[email protected]
9:41:29 PM: npm ERR! node_modules/@angular/compiler-cli
9:41:29 PM: npm ERR!   @angular/compiler-cli@"^14.0.2" from the root project
9:41:29 PM: npm ERR!   peer @angular/compiler-cli@"^14.0.0" from @angular-devkit/[email protected]
9:41:29 PM: npm ERR!   node_modules/@angular-devkit/build-angular
9:41:29 PM: npm ERR!     dev @angular-devkit/build-angular@"~14.0.3" from the root project
9:41:29 PM: npm ERR!   2 more (@angular/localize, @ngtools/webpack)
9:41:29 PM: npm ERR!
9:41:29 PM: npm ERR! Conflicting peer dependency: @angular/[email protected]
9:41:29 PM: npm ERR! node_modules/@angular/compiler
9:41:29 PM: npm ERR!   peer @angular/compiler@"14.2.6" from @angular/[email protected]
9:41:29 PM: npm ERR!   node_modules/@angular/compiler-cli
9:41:29 PM: npm ERR!     @angular/compiler-cli@"^14.0.2" from the root project
9:41:29 PM: npm ERR!     peer @angular/compiler-cli@"^14.0.0" from @angular-devkit/[email protected]
9:41:29 PM: npm ERR!     node_modules/@angular-devkit/build-angular
9:41:29 PM: npm ERR!       dev @angular-devkit/build-angular@"~14.0.3" from the root project
9:41:29 PM: npm ERR!
9:41:29 PM: Build was terminated: Build script returned non-zero exit code: 1
9:41:29 PM: Creating deploy upload records
9:41:29 PM: Failing build: Failed to build site
Top comments (0)



在此输入图像描述

angular netlify
3个回答
1
投票

一种可能的解决方案是使用

.npmrc
文件在安装过程中指定选项。

如果您还没有添加一个

.npmrc
文件到项目根目录,其中包含以下内容:

legacy-peer-deps=true

有关此选项作用的更多信息,请参阅: npm install --legacy-peer-deps 到底做什么?何时推荐/潜在的用例是什么?


0
投票

npm install 命令失败。清理你的 package.json 或尝试

npm install --force

要清理 package.json,请为所有角度库设置相同的角度版本。


0
投票

重新安装

node_modules
就解决了问题的一半。正确的做法是删除
node_modules
package-lock.json
。然后再次
npm install
生成新的
package-lock.json
文件。

我的案例是将 Angular 从 16 升级到 17,仅供参考。

© www.soinside.com 2019 - 2024. All rights reserved.