我想使用cordova file transfer plugin。我正在通过Ionic-Native transfer module使用它。
应用程序将不会运行,因为文件传输插件和

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插件文件包中的标识符重复,应用程序将无法运行:
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'.

这里正确的方法是什么?

最佳答案

如前所述,Cordova插件文件传输中的键入似乎不正确。
它应该是一个外部模块,但它当前是一个脚本文件(直接从definitelytyped复制)。
另一方面,由于cordova插件文件已经包含了它自己的类型,所以不需要安装@types/cordova插件文件。
我也经历过这个问题。
不过,我可以通过以下操作来解决这个问题:
设置:

```
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
```

解决问题的步骤:
移除平台
删除Cordova插件
重建项目
添加平台
删除Cordova插件文件传输插件
重建iOS项目
```
$ 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项目:
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 **
```

07-28 01:57
查看更多