我正在尝试将Router添加到一个项目,该项目在创建时并未对Router说是。 这是我正在运行的命令:
npm install -g @angular/router
这里是项目配置和命令结果:
Angular CLI: 9.1.1
Node: 10.15.1
OS: win32 x64
Angular: 9.1.2
... common, compiler, compiler-cli, core
Ivy Workspace: Yes
Package Version
-------------------------------------------------------------
@angular-devkit/architect 0.901.1
@angular-devkit/build-angular 0.901.1
@angular-devkit/build-ng-packagr 0.901.1
@angular-devkit/build-optimizer 0.901.1
@angular-devkit/build-webpack 0.901.1
@angular-devkit/core 9.1.1
@angular-devkit/schematics 9.1.1
@angular/animations 9.0.7
@angular/cdk 9.2.1
@angular/cli 9.1.1
@angular/flex-layout 9.0.0-beta.29
@angular/forms 9.0.7
@angular/language-service 9.0.7
@angular/material 9.2.1
@angular/platform-browser 9.0.7
@angular/platform-browser-dynamic 9.0.7
@angular/router 9.0.7
@ngtools/webpack 9.1.1
@schematics/angular 9.1.1
@schematics/update 0.901.1
ng-packagr 9.1.1
rxjs 6.5.5
typescript 3.7.5
webpack 4.42.0
PS D:\PrismNewUI\PrismWebUIUX> npm install -g @angular/router
npm WARN @angular/router@9.1.3 requires a peer of @angular/core@9.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@9.1.3 requires a peer of @angular/common@9.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@9.1.3 requires a peer of @angular/platform-browser@9.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@9.1.3 requires a peer of rxjs@^6.5.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@9.1.3 requires a peer of tslib@^1.10.0 but none is installed. You must install peer dependencies yourself.
+ @angular/router@9.1.3
updated 1 package in 0.482s
在我看来,当前的路由器版本高于我的项目。
据我了解,路由器尚未安装。在这种情况下我该怎么办?
谢谢
没有全局标志:
PS D:\PrismNewUI\PrismWebUIUX> npm install @angular/router
npm WARN @angular-devkit/build-ng-packagr@0.901.1 requires a peer of tsickle@~0.37.1 || ~0.38.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/animations@9.0.7 requires a peer of @angular/core@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/forms@9.0.7 requires a peer of @angular/core@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/forms@9.0.7 requires a peer of @angular/common@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser@9.0.7 requires a peer of @angular/core@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser@9.0.7 requires a peer of @angular/common@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser-dynamic@9.0.7 requires a peer of @angular/core@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser-dynamic@9.0.7 requires a peer of @angular/common@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser-dynamic@9.0.7 requires a peer of @angular/compiler@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @rollup/plugin-json@4.0.2 requires a peer of rollup@^1.20.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@8.0.2 requires a peer of node-sass@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@8.0.2 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-subresource-integrity@1.4.0 requires a peer of html-webpack-plugin@^2.21.0 || ~3 || >=4.0.0-alpha.2 <5 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@9.0.7 requires a peer of @angular/core@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@9.0.7 requires a peer of @angular/common@9.0.7 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules\watchpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ @angular/router@9.0.7
updated 1 package and audited 17382 packages in 11.929s
found 2 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
答案 0 :(得分:0)
npm install -g @angular/router
在您的计算机上全局安装路由器。基本上在Windows上,可以在%AppData%/npm
路径中找到全局安装的npm依赖项。如果全局安装的npm软件包具有命令行界面(如angular-cli
),则可以直接从外壳程序访问命令。
如果要将路由器安装在本地项目中,则可以“手动”将所需的版本添加到package.json
JSON条目中的dependencies
并从路径调用npm install
,其中可以找到package.json
。新添加的依赖项将下载到项目的node_modules
中。
或者,如果您不想“手动”将其添加到package.json
,则可以在项目npm install @angular/router@<wishedversion>
所在的路径上调用package.json
。这样,路由器将安装在node_modules
中,并且package.json
将被更新。 (当然,<wishedversion>
应该是您需要的版本。)
但是我在上面的依赖项中看到@angular/router: 9.0.7
。这意味着,它已经在package.json
中,因此仅需要从npm install
的路径进行一个package.json
调用,以将其安装在本地node_modules
中。