无法安装包 - ionic-native

Fail to install package - ionic-native

我正在关注 this link 将本地通知安装到我的 ionic 2 应用程序中。

首先我运行以下两个命令

Username@DESKTOP-BNKQVBC MINGW64 ~/Reminder-App (platform-specific)
$ npm install ionic-native --save
rxjs@5.0.1 node_modules\ionic-native\node_modules\rxjs -> node_modules\@ionic\cloud\node_modules\rxjs
ionic-hello-world@0.0.0 C:\Users\Username\Reminder-App
+-- @ionic/cloud-angular@0.12.0
| `-- @ionic/cloud@0.16.0
|   `-- ionic-native@2.9.0
`-- ionic-native@3.5.0

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN @ionic-native/background-mode@3.6.1 requires a peer of @ionic-native/core@^3.6.0 but none was installed.
npm WARN The package @ionic/cloud-angular is included as both a dev and production dependency.

Username@DESKTOP-BNKQVBC MINGW64 ~/Reminder-App (platform-specific)
$ npm install
        ionic-hello-world@0.0.0 C:\Users\Username\Reminder-App
+-- @ionic-native/core@3.8.0
+-- @ionic-native/splash-screen@3.6.0
`-- @ionic-native/status-bar@3.6.0

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN The package @ionic/cloud-angular is included as both a dev and production dependency.

之后我尝试运行遵循命令

npm install --save @ionic-native/local-notifications

但它给了我以下警告

Username@DESKTOP-BNKQVBC MINGW64 ~/Reminder-App (platform-specific)
$ npm install --save -g @ionic-native/local-notifications
C:\Users\Username\AppData\Roaming\npm
`-- @ionic-native/local-notifications@3.8.0

npm WARN @ionic-native/local-notifications@3.8.0 requires a peer of @ionic-native/core@^3.6.0 but none was installed.
npm WARN @ionic-native/local-notifications@3.8.0 requires a peer of @angular/core@* but none was installed.
npm WARN @ionic-native/local-notifications@3.8.0 requires a peer of rxjs@^5.0.1 but none was installed.

但是我已经安装了这些依赖项

"dependencies": {
    "@angular/common": "4.0.2",
    "@angular/compiler": "4.0.2",
    "@angular/compiler-cli": "4.0.2",
    "@angular/core": "4.0.2",
    "@angular/forms": "4.0.2",
    "@angular/http": "4.0.2",
    "@angular/platform-browser": "4.0.2",
    "@angular/platform-browser-dynamic": "4.0.2",
    "@ionic-native/background-mode": "^3.6.1",
    "@ionic-native/core": "^3.6.0",
    "@ionic-native/splash-screen": "3.6.0",
    "@ionic-native/status-bar": "3.6.0",
    "@ionic/cloud-angular": "^0.12.0",
    "@ionic/storage": "^2.0.1",
    "ionic-angular": "3.1.0",
    "ionic-native": "^3.5.0",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "^0.8.5"
  }

任何人都可以指导我我错过了什么吗?

查看 npm documentation

1) It was due to that the packages were not installed globally ?

是的。更准确地说,npm 没有在全局 node_modules 文件夹中找到 @ionic-native/local-notifications 所需的对等依赖项,这就是为什么它发出警告,即使包存在于您的本地项目中。

2) Can you let me know when to use -g and when not to ?

这取决于您是否需要某些包来开发多个项目而不是特定的包,尤其是那些可以在命令行中 运行 的包。 typescriptionic(cli) 等软件包是全局安装的。

根据文档:

If you want to use it as a command line tool, something like the grunt CLI, then you want to install it globally. On the other hand, if you want to depend on the package from your own module using something like Node's require, then you want to install locally.

您的命令必须是:

npm install --save @ionic-native/local-notifications

没有 -g.