You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2020/07/01 09:33:11 UTC

[GitHub] [cordova] cagross opened a new issue #222: Cordova build fails if I set 'type: modules' in package.json.

cagross opened a new issue #222:
URL: https://github.com/apache/cordova/issues/222


   # Bug Report
   
   ## Problem
   
   ### What is expected to happen?
   `cordova build android` completes without issue.
   
   
   ### What does actually happen?
   Build fails with the following output:
   
       $ cordova build android
       Unable to load PlatformApi from platform. Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\snarl\my-project\platforms\android\cordova\Api.js
       require() of ES modules is not supported.
       require() of C:\Users\snarl\my-project\platforms\android\cordova\Api.js from C:\Users\snarl\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\util.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
       Instead rename Api.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\snarl\my-project\package.json.
       
       Unhandled error. ('The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.')
   
   
   ## Information
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   
   I've built a simple app, which I can build for Android (or browser) without issue.  I have now now implemented a simple unit test (using [Tape](https://github.com/substack/tape)), which runs in Node.  Since some files I'm testing are ES6 modules, in order to run the unit tests in Node, I had to add `"type": "module",` to my `package.json` file.  But when I did that, my app would no longer build--the Cordova build command fails with the output above.  Is it possible to execute the Cordova build for Android--if so, how?
   
   Or is some part of my method flawed in this case? That is certainly a possibility.  Maybe if I run unit tests in the browser (rather than in Node), this issue will be avoided?
   
   Thanks.
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   
   `cordova build android` (or `cordova build browser`)
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   
   Platforms:  Android, Browser
   
   ### Version information
   Cordova: 9.0.0 (cordova-lib@9.0.1)
   Cordova Plugins:  cordova-plugin-file, cordova-plugin-network-information, cordova-plugin-whitelist
   Other Frameworks: 
   Operating System:  Windows
   
   
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [ X ] I searched for existing GitHub issues
   - [ X ] I updated all Cordova tooling to most recent version
   - [ X ] I included all the necessary information above
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org