【问题标题】:I cant install the Camera in Ionic v3我无法在 Ionic v3 中安装相机
【发布时间】:2019-03-11 00:52:45
【问题描述】:

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

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)

【问题讨论】:

  • 我也得到了这个 :c 类型参数 '{ 声明:(typeof HomePage | typeof MyApp)[];进口:(ModuleWithProviders | typeof Browse...' 不可分配给'NgModule'类型的参数。属性'providers'的类型不兼容。类型'(typeof SplashScreen | CameraOriginal | {提供:typeof ErrorHandler; useClass:typeof IonicErr。 ..' 不可分配给类型 'Provider[]'。类型 'typeof SplashScreen | CameraOriginal | { 提供:typeof ErrorHandler; useClass: typeof IonicErro...' 不可分配给类型 'Provider'。类型 'CameraOriginal' 不是可分配给类型“提供者”
  • 即使在 ionic 4 发布后我也无法在 Ionic 3 中安装插件

标签: npm ionic3 cordova-plugins ionic-native


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    并尝试安装camera

    ionic cordova plugin add cordova-plugin-camera

    npm install --save @ionic-native/camera

    在进行其他步骤之前,请检查它们是否添加或在package.json 和config.xml 中

    【讨论】:

    • 您好!运行 npm i @ionic-native/core 后,我仍然收到以下消息:npm WARN @ionic-native/camera@5.0.0 需要 @ionic-native/core@5.0.0 的对等点,但没有安装。您必须自己安装对等依赖项。 npm WARN 可选跳过可选依赖:fsevents@1.2.7 (node_modules/fsevents):npm WARN notsup 跳过可选依赖:fsevents@1.2.7 不支持的平台:想要 {"os":"darwin","arch":"any "} (current: {"os":"linux","arch":"x64"}) + @ionic-native/core@4.3.2 更新了1个包,4.61s审核了6811个包
    猜你喜欢
    • 2017-04-28
    • 1970-01-01
    • 2019-08-17
    • 2018-11-26
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 2017-09-21
    相关资源
    最近更新 更多