使用 cordova-plugin-file-transfer 编译错误

时间:2023-01-31
本文介绍了使用 cordova-plugin-file-transfer 编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想使用 cordova 文件传输插件.我通过 Ionic-Native 传输模块 使用它.

I want to use the cordova file transfer plugin. I'm using it through the Ionic-Native transfer module.

应用程序无法运行,因为文件传输插件和 文件插件:

The app won't run because there is a transpile error with the file transfer plugin and the file plugin:

transpile started ... 
typescript: plugins/cordova-plugin-file-transfer/types/index.d.ts, line: 9 
Cannot find type definition file for 'cordova-plugin-file'. 

L8:  * @param server            URL of the server to receive the file, as encoded by encodeURI().
L9:  * @param successCallback   A callback that is passed a FileUploadResult object.
L10: * @param errorCallback     A callback that executes if an error occurs retrieving the FileUploadResult.

我通过 npm 安装了 @types/cordova-plugin-file,但由于两个 cordova-plugin-file 包中的标识符重复,应用程序无法运行:

I installed @types/cordova-plugin-file through npm, but the app won't run because of duplicate identifiers in the two cordova-plugin-file packages:

transpile started ... 
typescript: node_modules/@types/cordova-plugin-file/index.d.ts, line: 376 
Duplicate identifier 'PERSISTENT'. 

typescript: node_modules/@types/cordova-plugin-file/index.d.ts, line: 377 
Duplicate identifier 'TEMPORARY'. 

typescript: plugins/cordova-plugin-file/types/index.d.ts, line: 376 
Duplicate identifier 'PERSISTENT'.     

typescript: plugins/cordova-plugin-file/types/index.d.ts, line: 377 
Duplicate identifier 'TEMPORARY'.

这里的正确方法是什么?

What is the right approach here?

推荐答案

如前所述,cordova-plugin-file-transfer 中的类型似乎不正确.

As mentioned, it looks like the typings in cordova-plugin-file-transfer are incorrect.

它应该是一个外部模块,但它目前是一个脚本文件(直接从DefiniteTyped复制).

It should be an external module but it is currently a script file (copied from DefinitelyTyped directly).

另一方面,由于 cordova-plugin-file 已经包含了自己的类型,你不需要安装 @types/cordova-plugin-file.

On the other hand, since cordova-plugin-file already includes its own typings, you don't need to install @types/cordova-plugin-file.

我也遇到过这个问题.

但是我能够通过以下操作解决该问题:

However I was able to work around the issue with the following operations:

设置:

```
Your system information:

Cordova CLI: 6.5.0 
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.2.1
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v7.7.4
Xcode version: Xcode 8.2.1 Build version 8C1002

```

最初的问题:

```
$ ionic build ios

Running 'build:before' npm script before build

> apoc@ build /Users/js/dev/apoc-ochem/app_v3/apoc
> ionic-app-scripts build

[01:47:59]  ionic-app-scripts 1.2.1 
[01:47:59]  build dev started ... 
[01:47:59]  clean started ... 
[01:47:59]  clean finished in 2 ms 
[01:47:59]  copy started ... 
[01:47:59]  transpile started ... 
[01:48:04]  typescript: plugins/cordova-plugin-file-transfer/types/index.d.ts, line: 9 
            Cannot find type definition file for 'cordova-plugin-file'. 

       L8:  * @param server            URL of the server to receive the file, as encoded by encodeURI().
       L9:  * @param successCallback   A callback that is passed a FileUploadResult object.
      L10:  * @param errorCallback     A callback that executes if an error occurs retrieving the FileUploadResult.

[01:48:04]  ionic-app-script task: "build" 
[01:48:04]  Error: Failed to transpile program 
Error: Failed to transpile program
    at new BuildError (/Users/js/dev/apoc-ochem/app_v3/apoc/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
    at /Users/js/dev/apoc-ochem/app_v3/apoc/node_modules/@ionic/app-scripts/dist/transpile.js:102:20
    at transpileWorker (/Users/js/dev/apoc-ochem/app_v3/apoc/node_modules/@ionic/app-scripts/dist/transpile.js:68:12)
    at Object.transpile (/Users/js/dev/apoc-ochem/app_v3/apoc/node_modules/@ionic/app-scripts/dist/transpile.js:26:12)
    at buildProject (/Users/js/dev/apoc-ochem/app_v3/apoc/node_modules/@ionic/app-scripts/dist/build.js:98:78)
    at /Users/js/dev/apoc-ochem/app_v3/apoc/node_modules/@ionic/app-scripts/dist/build.js:46:16

npm ERR! Darwin 16.4.0
npm ERR! argv "/Users/js/.nvm/versions/node/v7.7.4/bin/node" "/Users/js/.nvm/versions/node/v7.7.4/bin/npm" "run" "build"
npm ERR! node v7.7.4
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! apoc@ build: `ionic-app-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the apoc@ build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the apoc package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs apoc
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls apoc
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!

 /Users/js/dev/apoc-ochem/app_v3/apoc/npm-debug.log
```

解决步骤:

  1. 移除平台
  2. 移除 Cordova 插件
  3. 重建项目
  4. 添加平台
  5. 移除 cordova-plugin-file-transfer 插件
  6. 重建ios项目

  1. Remove Platform
  2. Remove Cordova plugin
  3. Rebuild project
  4. Add Platform
  5. Remove cordova-plugin-file-transfer plugin
  6. Rebuild ios project

```
$ cordova plugin rm cordova-plugin-file-transfer
Removing "cordova-plugin-file-transfer"
$ ionic build ios

...
...


[02:01:20]  lint finished in 3.70 s 
Error: No platforms added to this project. Please use `cordova platform add <platform>`.


$ ionic platforms add ios

正在添加 ios 项目...为 iOS 平台创建 Cordova 项目:

Adding ios project... Creating Cordova project for the iOS platform:

Path: platforms/ios

Package: com.nielssievertsen.apocsocial
Name: apoc social


iOS project created with cordova-ios@4.3.1


Installing "com.synconset.imagepicker" for ios


Installing "cordova-plugin-camera" for ios


Fetching plugin "cordova-plugin-compat" via npm


Installing "cordova-plugin-compat" for ios


Installing "cordova-plugin-console" for ios


Installing "cordova-plugin-device" for ios


Installing "cordova-plugin-device-motion" for ios


Installing "cordova-plugin-facebook4" for ios


Installing "cordova-plugin-googleplus" for ios


Google Sign-In prerequisites

START Running hook to add iOS Keychain Sharing entitlements (required since iOS 10)

Will add iOS Keychain Sharing entitlements to project 'apoc social'

END Running hook to add iOS Keychain Sharing entitlements (required since iOS 10)

Installing "cordova-plugin-media-capture" for ios


Fetching plugin "cordova-plugin-file" via npm


Installing "cordova-plugin-file" for ios


Dependent plugin "cordova-plugin-compat" already installed on ios.


Dependent plugin "cordova-plugin-compat" already installed on ios.


Installing "cordova-plugin-nativestorage" for ios


Installing "cordova-plugin-shake" for ios


Dependent plugin "cordova-plugin-device-motion" already installed on ios.


Installing "cordova-plugin-splashscreen" for ios


Installing "cordova-plugin-statusbar" for ios


Installing "cordova-plugin-whitelist" for ios


Installing "cordova-sqlite-storage" for ios


installing external dependencies via npm

npm install of external dependencies ok

Installing "ionic-plugin-keyboard" for ios


Installing "phonegap-plugin-push" for ios


Discovered plugin "cordova-plugin-file-transfer" in config.xml. Adding it to the project


Fetching plugin "cordova-plugin-file-transfer@~1.6.1" via npm


Installing "cordova-plugin-file-transfer" for ios


Dependent plugin "cordova-plugin-file" already installed on ios.

$ cordova plugin rm cordova-plugin-file-transfer


Uninstalling cordova-plugin-file-transfer from ios
Removing "cordova-plugin-file-transfer"
"cordova-plugin-file" is required by (cordova-plugin-media-capture) and cannot be removed (hint: use -f or --force)
"cordova-plugin-compat" is required by (cordova-plugin-camera, cordova-plugin-media-capture) and cannot be removed (hint: use -f or --force)


$ ionic build ios


............
...

** BUILD SUCCEEDED **
```

这篇关于使用 cordova-plugin-file-transfer 编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 ionic 2 应用程序中更改 iOS 状态栏颜色 下一篇:离子 - svg 不出现

相关文章

最新文章