我无法在Ionic v3中安装相机

时间:2019-01-27 02:25:22

标签: npm ionic3 cordova-plugins ionic-native

我正在构建一个想要使用cordova相机插件的Ionic应用程序,因此我输入:

ionic cordova plugin add cordova-plugin-camera

然后我这样做:

npm install --save @ionic-native/camera

我在这里收到此警告:

npm WARN @ionic-native/camera@5.0.0 requires a peer of @ionic-native/core@5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

之后,当我在app.module和提供者列表中包括照相机插件时,我将收到此消息:

Error: Invalid provider for the NgModule 'AppModule' - only instances of Provider and Type are allowed, got: [StatusBar, SplashScreen, [object Object], ?[object Object]?]
at syntaxError (http://localhost:8100/build/vendor.js:74769:34)
at http://localhost:8100/build/vendor.js:89925:40
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/vendor.js:89893:19)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:89463:50)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:107787:87)
at JitCompiler._compileModuleAndComponents (http://localhost:8100/build/vendor.js:107748:36)
at JitCompiler.compileModuleAsync (http://localhost:8100/build/vendor.js:107664:37)
at CompilerImpl.compileModuleAsync (http://localhost:8100/build/vendor.js:73605:49)
at PlatformRef.bootstrapModule (http://localhost:8100/build/vendor.js:5747:25)

2 个答案:

答案 0 :(得分:1)

由于Ionic 4的发布,在安装Ionic 3时,为Ionic 3安装Ionic Native插件需要附加@4。因此,要解决此问题,请使用npm uninstall --save @ionic-native/camera卸载该插件,然后使用{ {1}},问题将得到解决。

答案 1 :(得分:0)

您已经错过了ionic/core依赖模块。因此,通过以下命令安装它们 npm i @ionic-native/core

并尝试安装camera

ionic cordova plugin add cordova-plugin-camera

npm install --save @ionic-native/camera

,并且在继续执行其他步骤之前,请检查它们是否在package.jsonconfig.xml

中添加或添加。