我是编码新手,我想开始在我的 M1 MacBook 上使用 Angular。
Angular cli 的安装仅取得了一定的成功,因为我在输入
sudo npm install -g @angular/cli
: 后收到此警告
npm WARN 已弃用@npmcli/[电子邮件受保护]:此功能已移至@npmcli/fs
...但是必须安装 Angular,因为我在输入后收到此消息
ng v
:
❯ ng v
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 15.1.5
Node: 18.14.0
Package Manager: npm 9.3.1
OS: darwin arm64
Angular: undefined
...
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1501.5 (cli-only)
@angular-devkit/core 15.1.5 (cli-only)
@angular-devkit/schematics 15.1.5 (cli-only)
@schematics/angular 15.1.5 (cli-only)
但是当我在终端中输入
ng new Hello-World
创建新项目时,我收到此错误消息:
⠴ Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: rxjs@undefined
npm ERR! node_modules/rxjs
npm ERR! rxjs@"~7.8.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer rxjs@"^6.5.3 || ^7.4.0" from @angular/[email protected]
npm ERR! node_modules/@angular/core
npm ERR! @angular/core@"^15.1.0" from the root project
npm ERR! peer @angular/core@"15.1.4" from @angular/[email protected]
npm ERR! node_modules/@angular/animations
npm ERR! @angular/animations@"^15.1.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! For a full report see:
npm ERR! /Users/cez/.npm/_logs/2023-02-15T12_35_49_149Z-eresolve-report.txt
据我了解,问题是我的rxjs版本是~7.8.0(可以通过查看package.json文件来确认),而7.8.0不在^6.5.3 ||之间^7.4.0,因此太新了。但我该如何解决这个问题呢?
以下是我安装的一些可能相关的版本。
❯ node --version
v18.14.0
❯ npm --version
9.3.1
我希望有人能帮我解决这个问题。
我已尝试按照错误消息的提示运行
ng new Hello-World --force
。我收到这条消息:
⠧ Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: rxjs@undefined
npm ERR! node_modules/rxjs
npm ERR! rxjs@"~7.8.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer rxjs@"^6.5.3 || ^7.4.0" from @angular/[email protected]
npm ERR! node_modules/@angular/core
npm ERR! @angular/core@"^15.1.0" from the root project
npm ERR! peer @angular/core@"15.1.4" from @angular/[email protected]
npm ERR! node_modules/@angular/animations
npm ERR! @angular/animations@"^15.1.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! /Users/cez/.npm/_logs/2023-02-15T12_55_47_782Z-eresolve-report.txt
我也尝试运行
ng new Hello-World --legacy-peer-deps
但没有任何结果
它给了我这样的信息:
错误:未知参数:legacy-peer-deps
我删除了 npm 缓存并开始工作。 运行这个命令:
sudo npm cache clean --force
然后使用
ng new my-app
创建新的角度应用程序