我想使用cordova file transfer plugin。我通过Ionic-Native transfer module使用它。
应用程序无法运行,因为文件传输插件和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包中的重复标识符,应用程序无法运行:
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'.
这里的正确方法是什么?
答案 0 :(得分:3)
如上所述,看起来cordova-plugin-file-transfer中的输入不正确。
它应该是一个外部模块,但它目前是一个脚本文件(直接从DefinitelyTyped复制)。
另一方面,由于cordova-plugin-file已经包含了自己的类型,因此您不需要安装@ types / cordova-plugin-file。
我也遇到过这个问题。
但是我能够通过以下操作解决问题:
设置:
```
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
```
解决方法的步骤:
重建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 **
```
答案 1 :(得分:2)
看起来cordova-plugin-file-transfer
中的输入不正确。
它应该是一个外部模块,但它目前是一个脚本文件(直接从DefinitelyTyped复制)。
你应该在那里提出问题。
另一方面,由于cordova-plugin-file
已经包含了自己的打字,因此您无需安装@types/cordova-plugin-file
。
答案 2 :(得分:2)
似乎“plugin /”文件夹是ionic2的cordova插件,你可能不需要执行打字稿编译,
您始终可以通过从tsconfig.json
指定排除目标来忽略index.d.ts答案 3 :(得分:0)
对于Ionic,有一个名为tsconfig.build.json的文件
在它的编译器选项中添加以下参数。
"skipLibCheck": true
它应该看起来像这样
{
"extends": "...anytest....",
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"skipLibCheck": true
},
"exclude": [
"...your config here..."
]
}