Transpile errors with cordova-plugin-file-transfer

≯℡__Kan透↙ 提交于 2021-02-07 09:20:25

问题


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.

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?


回答1:


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

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

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

I experienced this issue as well.

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

Setup :

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

```

Initial Problem :

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

Steps for Work Around:

  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
    

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



回答2:


Looks like the typings in cordova-plugin-file-transfer is incorrect.

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

You should file an issue there.

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




回答3:


It seems the "plugin/" folder is cordova plugins for ionic2, which you may not need to perform typescript compilation,

You can always ignore the index.d.ts by specifying the exclude target from tsconfig.json




回答4:


For Ionic there is file called tsconfig.build.json

in it compiler option add below parameter.

 "skipLibCheck": true

it should look like this

{
  "extends": "...anytest....",
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "skipLibCheck": true
  },
  "exclude": [
    "...your config here..."
  ]
}


来源:https://stackoverflow.com/questions/42882090/transpile-errors-with-cordova-plugin-file-transfer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!