cordova-mobile-spec
cordova-mobile-spec copied to clipboard
mobile-spec project creation fails with error "Cannot find module 'cordova-common'"
mobile-spec project creation fails with the error "Error: Cannot find module 'cordova-common'" when trying to execute the command - "node ./cordova-mobile-spec/createmobilespec/createmobilespec.js --android --forceplugins"
If I try adding cordova-common module in mobile-spec project manually and try executing the platform add command using - "root_folder\cordova-cli\bin\cordova.cmd platform add "root_folder\cordova-android" --verbose" , platform addition is successfully.
Not sure how to bring in cordova-common module installed as dependency while creating mobile-spec project
How did you setup your Cordova folders with all the checkouts before running this command? What does "try addinv cordova-common mobile in mobile-spec project manually" mean?
@janpio I just checked out all the repos to a root folder using coho repo update. In the mobile-spec project, I did 'npm install cordova-common'
Please install a new node version (to make sure there are not more global tools installed), create a new "Cordova" folder, use coho to check out all repositories there, then create a new mobile-spec project. Report each problem you encounter please and document all the commands you run. Thanks.
@janpio Hi Jan, following are the detailed steps I tried:
- Installed latest node version v10.14.0
- Created a new root folder named "cordova_src"
- Navigated to root folder and ran the command - "coho repo-update -g -r all"
- Navigated to 'cordova-cli' inside root folder and ran the command - "npm install"
- Navigated to 'cordova-common' inside root folder and ran the command - "npm install"
- Navigated to 'cordova-js' inside root folder and ran the command - "npm install"
- Navigated to 'cordova-android' inside root folder and ran the command - "npm install"
- Navigated to 'cordova-mobile-spec\createmobilespec' inside root folder and ran the command - "npm install"
- Navigated to root folder and ran the command - "node ./cordova-mobile-spec/createmobilespec/createmobilespec.js --android --forceplugins"
On following these steps, i got the error - "Error: Module cordova-lib installed in cordova-plugman is not npm-linked. I recommend you run "coho npm-link".
Even if i run coho npm-link from root folder or from cordova-plugman folder, this issue still exists.
NOTE: I also get an error stating "Error: Cannot find module 'elementtree'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.
when I run cordova -version command from root folder. Am i missing something in installation and setup?
Steps 4-7 are not necessary, the first error you get also a problem of outdated instructions.
Please check the updated READMEs at https://github.com/apache/cordova-mobile-spec and https://github.com/apache/cordova-mobile-spec/tree/master/createmobilespec. My PR got merged a few hours ago.
@janpio
D:\Gandhi\Cordova\Cordova_git>node cordova-mobile-spec/createmobilespec/createmobilespec.js --android
### Creating project from local git repos. If you have any errors, it may be from missing repositories.
To clone repositories:
.\cordova-coho\coho repo-clone -r mobile-spec -r plugin-test-framework -r cli -r lib -r plugman -r android -r js -r plugins
mkdir cordova-cli\node_modules
(cd cordova-lib && npm install)
(cd cordova-plugman\ && npm install)
mkdir cordova-cli\node_modules
ln -s ..\..\cordova-lib cordova-cli\node_modules
(cd cordova-cli && npm install)
To update all repositories:
.\cordova-coho\coho repo-update
Checking if you are using master branch of tools (js, lib, plugman, cli)
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
You are on master branch of tools, checking npm links
npm links are OK
### Creating project mobilespec...
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova create mobilespec org.apache.cordova.mobilespec MobileSpec_Tests --template cordova-mobile-spec\www
Warning: using prerelease version 8.0.1-dev ([email protected])
Creating a new cordova project.
### Adding platforms...
### Adding Platform: android
platformArg: D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova D:\Gandhi\Cordova\Cordova_git\cordova-android
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova platform add "D:\Gandhi\Cordova\Cordova_git\cordova-android" --verbose
Warning: using prerelease version 8.0.1-dev ([email protected])
No scripts found for hook "before_platform_add".
fetch: Installing D:\Gandhi\Cordova\Cordova_git\cordova-android to D:\Gandhi\Cordova\Cordova_git\mobilespec
Running command: npm install D:\Gandhi\Cordova\Cordova_git\cordova-android --production --save
Command finished with error code 0: npm install,D:\Gandhi\Cordova\Cordova_git\cordova-android,--production,--save
Removing "cordova-" prefix from cordova-android
Warning: using prerelease platform [email protected].
Use 'cordova platform add android@latest' to add the latest published version instead.
Adding android project...
PlatformApi successfully found for platform android
Creating Cordova project for the Android platform:
Path: platforms\android
Package: org.apache.mobilespec
Name: mobilespec
Activity: MainActivity
Android target: android-27
Copying android template project to platforms\android
Cannot find module 'cordova-common'
Error: Cannot find module 'cordova-common'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (D:\Gandhi\Cordova\Cordova_git\mobilespec\platforms\android\cordova\lib\builders\builders.js:20:22)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
### Updating js for platforms...
$ "D:\Installers\nodejs_latest\node.exe" D:\Gandhi\Cordova\Cordova_git\cordova-mobile-spec\createmobilespec\node_modules\grunt-cli\bin\grunt compile:android --platformVersion=8.0.0-dev
Running "compile:android" (compile) task
generated cordova.android.js @ 9490096bb175b2c04b614e40fecf7b7622522489 in 30ms
Done.
JavaScript file updated for android
### Adding plugins using CLI...
Searchpath: D:\Gandhi\Cordova\Cordova_git\
Installing local test framework plugins...
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add org.apache.cordova.test.echo --searchpath D:\Gandhi\Cordova\Cordova_git\cordova-mobile-spec
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "org.apache.cordova.test.echo" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'org.apache.cordova.test.echo': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-test-framework
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-test-framework" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-test-framework': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-device
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-device" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-device': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-whitelist
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-whitelist" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-whitelist': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-battery-status
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-battery-status" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-battery-status': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
Hi @janpio , I followed the exact steps as mentioned in the link - https://github.com/apache/cordova-mobile-spec/blob/master/createmobilespec/README.md#requirements-and-preparation
While trying to execute the command - "node cordova-mobile-spec/createmobilespec/createmobilespec.js --android", I m still getting the same error as mentioned earlier.
The complete error trace is as follows:
D:\Gandhi\Cordova\Cordova_git>node cordova-mobile-spec/createmobilespec/createmobilespec.js --android
### Creating project from local git repos. If you have any errors, it may be from missing repositories.
To clone repositories:
.\cordova-coho\coho repo-clone -r mobile-spec -r plugin-test-framework -r cli -r lib -r plugman -r android -r js -r plugins
mkdir cordova-cli\node_modules
(cd cordova-lib && npm install)
(cd cordova-plugman\ && npm install)
mkdir cordova-cli\node_modules
ln -s ..\..\cordova-lib cordova-cli\node_modules
(cd cordova-cli && npm install)
To update all repositories:
.\cordova-coho\coho repo-update
Checking if you are using master branch of tools (js, lib, plugman, cli)
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
You are on master branch of tools, checking npm links
npm links are OK
### Creating project mobilespec...
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova create mobilespec org.apache.cordova.mobilespec MobileSpec_Tests --template cordova-mobile-spec\www
Warning: using prerelease version 8.0.1-dev ([email protected])
Creating a new cordova project.
### Adding platforms...
### Adding Platform: android
platformArg: D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova D:\Gandhi\Cordova\Cordova_git\cordova-android
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova platform add "D:\Gandhi\Cordova\Cordova_git\cordova-android" --verbose
Warning: using prerelease version 8.0.1-dev ([email protected])
No scripts found for hook "before_platform_add".
fetch: Installing D:\Gandhi\Cordova\Cordova_git\cordova-android to D:\Gandhi\Cordova\Cordova_git\mobilespec
Running command: npm install D:\Gandhi\Cordova\Cordova_git\cordova-android --production --save
Command finished with error code 0: npm install,D:\Gandhi\Cordova\Cordova_git\cordova-android,--production,--save
Removing "cordova-" prefix from cordova-android
Warning: using prerelease platform [email protected].
Use 'cordova platform add android@latest' to add the latest published version instead.
Adding android project...
PlatformApi successfully found for platform android
Creating Cordova project for the Android platform:
Path: platforms\android
Package: org.apache.mobilespec
Name: mobilespec
Activity: MainActivity
Android target: android-27
Copying android template project to platforms\android
Cannot find module 'cordova-common'
Error: Cannot find module 'cordova-common'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (D:\Gandhi\Cordova\Cordova_git\mobilespec\platforms\android\cordova\lib\builders\builders.js:20:22)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
### Updating js for platforms...
$ "D:\Installers\nodejs_latest\node.exe" D:\Gandhi\Cordova\Cordova_git\cordova-mobile-spec\createmobilespec\node_modules\grunt-cli\bin\grunt compile:android --platformVersion=8.0.0-dev
Running "compile:android" (compile) task
generated cordova.android.js @ 9490096bb175b2c04b614e40fecf7b7622522489 in 30ms
Done.
JavaScript file updated for android
### Adding plugins using CLI...
Searchpath: D:\Gandhi\Cordova\Cordova_git\
Installing local test framework plugins...
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add org.apache.cordova.test.echo --searchpath D:\Gandhi\Cordova\Cordova_git\cordova-mobile-spec
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "org.apache.cordova.test.echo" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'org.apache.cordova.test.echo': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-test-framework
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-test-framework" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-test-framework': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-device
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-device" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-device': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-whitelist
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-whitelist" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-whitelist': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
$ D:\Gandhi\Cordova\Cordova_git\cordova-cli\bin\cordova plugin add D:\Gandhi\Cordova\Cordova_git\cordova-plugin-battery-status
Warning: using prerelease version 8.0.1-dev ([email protected])
Installing "cordova-plugin-battery-status" for android
Unable to load PlatformApi from platform. Error: Cannot find module 'q'
Failed to install 'cordova-plugin-battery-status': Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
at EventEmitter.emit (events.js:171:17)
at EventEmitter.module.exports.emit (D:\Gandhi\Cordova\Cordova_git\cordova-common\src\events.js:71:17)
at Object.getPlatformApiFunction (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\cordova\util.js:370:20)
at Object.getPlatformApi (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\platforms\platforms.js:55:32)
at handleInstall (D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:580:29)
at D:\Gandhi\Cordova\Cordova_git\cordova-lib\src\plugman\install.js:349:28
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)
Am i missing any prerequisites? Any thoughts?
I recall having this issue when testing with master branch of cordova-android. For now can you try it on the 7.1.x branch?
@brodybits Hi Chris, Thanks for the response. This was working for me couple of patches back. Could you please let me know the exact branch path and what needs to be updated to get it tested for a specific version?
On Sun, Dec 2, 2018, 9:24 AM Gandhirajan [email protected] wrote:
@brodybits https://github.com/brodybits Hi Chris, Thanks for the response. This was working for me couple of patches back.
I would suggest divide and can conquer to help pinpoint where it went wrong.
I would sometimes go back to where it was working and then move forward 20-30 % at a time to find the point of failure.
We want to test what we will release before releasing it.
Thanks @gandhirajan, now that you have set it up following the new instructions, we have something we can compare. When I find the time, I will try to reproduce again.
If what @brodybits says applies, switching cordova-android
to the 7.1.x
branch should be enough.
@gandhirajan I can reproduce what you are getting for --android
.
For --browser
it works with no errors, which probably means that the error is not generally with createmobilespec.js
, but in the specific conditions of --android
- which is a good thing.
Update: tried --ios
as well, which has also has problems with a missing package, but a different one than --android
:
...
Command finished with error code 0: npm install,C:\Projects\cordova5\cordova-ios,--production,--save
Removing "cordova-" prefix from cordova-ios
Warning: using prerelease platform [email protected].
Use 'cordova platform add ios@latest' to add the latest published version instead.
Adding ios project...
PlatformApi successfully found for platform ios
Creating Cordova project for the iOS platform:
Path: platforms\ios
Package: org.apache.mobilespec
Name: mobilespec
Copying iOS template project to C:\Projects\cordova5\mobilespec\platforms\ios
iOS project created with [email protected]
Cannot find module 'unorm'
Error: Cannot find module 'unorm'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\Projects\cordova5\mobilespec\platforms\ios\cordova\Api.js:24:13)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
### Updating js for platforms...
$ "C:\Program Files\nodejs\node.exe" C:\Projects\cordova5\cordova-mobile-spec\createmobilespec\node_modules\grunt-cli\bin\grunt compile:ios --platformVersion=5.0.0-dev
Running "compile:ios" (compile) task
...
And what @brodybits suggested with switching to cordova-android
7.1.x (git checkout 7.1.x
in /cordova-android
) indeed fixes the problem and makes the script succeed for Android.
That should give us some information to understand what is going wrong here.
Investigation where the error is coming from:
- Recreate the problem manually:
C:\Projects\cordova5
λ C:\Projects\cordova5\cordova-cli\bin\cordova create mobilespec_ios_manual org.apache.cordova.mobilespec MobileSpec_Tests --template cordova-mobile-spec\www
Warning: using prerelease version 8.0.1-dev ([email protected])
Creating a new cordova project.
C:\Projects\cordova5
λ cd mobilespec_ios_manual
C:\Projects\cordova5\mobilespec_ios_manual
λ C:\Projects\cordova5\cordova-cli\bin\cordova platform add "C:\Projects\cordova5\cordova-ios" --verbose
Warning: using prerelease version 8.0.1-dev ([email protected])
No scripts found for hook "before_platform_add".
fetch: Installing C:\Projects\cordova5\cordova-ios to C:\Projects\cordova5\mobilespec_ios_manual
Running command: npm install C:\Projects\cordova5\cordova-ios --production --save
Command finished with error code 0: npm install,C:\Projects\cordova5\cordova-ios,--production,--save
Removing "cordova-" prefix from cordova-ios
Warning: using prerelease platform [email protected].
Use 'cordova platform add ios@latest' to add the latest published version instead.
Adding ios project...
PlatformApi successfully found for platform ios
Creating Cordova project for the iOS platform:
Path: platforms\ios
Package: org.apache.cordova.mobilespec
Name: MobileSpec_Tests
Copying iOS template project to C:\Projects\cordova5\mobilespec_ios_manual\platforms\ios
iOS project created with [email protected]
Cannot find module 'unorm'
Error: Cannot find module 'unorm'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\Projects\cordova5\mobilespec_ios_manual\platforms\ios\cordova\Api.js:24:13)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
- Last output before error is
iOS project created with [email protected]
.
Code for this lives at: https://github.com/apache/cordova-ios/blob/62ebfbd74aff11b9fa0ca26685ee0578ecd9150f/bin/lib/create.js#L255-L262 ... which is the last call ofcreateProject
: https://github.com/apache/cordova-ios/blob/62ebfbd74aff11b9fa0ca26685ee0578ecd9150f/bin/lib/create.js#L198-L239 ... which is called increatePlatform
: https://github.com/apache/cordova-ios/blob/2cd93097ec5d5989bc758f15db75011829c84c2b/bin/templates/scripts/cordova/Api.js#L113-L135 - So we know what happens after that output: https://github.com/apache/cordova-ios/blob/2cd93097ec5d5989bc758f15db75011829c84c2b/bin/templates/scripts/cordova/Api.js#L124-L129
- The crashing command seems to be:
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
This requires C:\Projects\cordova5\mobilespec_ios_manual\platforms\ios\cordova\Api.js
in this case (which is the same file being executed, but now inside the installed platform). unorm
is the first dependency "non-system" dependency in this file.
- Yep, for
cordova-android
the first require in the file iscordova-common
: https://github.com/apache/cordova-android/blob/8a4ae311ce165e31f0511ae43274aa52d3773fd2/bin/templates/cordova/Api.js#L24
So now I know why this is crashing: Api.js
in the platform does not have its dependencies available. Now to find out why.
I now have 2 apps with the Android platform added, one with master
and one with 7.1.x
: master
is missing node_modules
in platforms/android/cordova
(which is created from https://github.com/apache/cordova-android/tree/master/bin/templates/cordova).
In 7.1.x this was copied there with this line: https://github.com/apache/cordova-android/blob/7.1.x/bin/lib/create.js#L171
In master
this is behind if (options.copyPlatformNodeModules)
:
https://github.com/apache/cordova-android/blob/master/bin/lib/create.js#L171
This was added in https://github.com/apache/cordova-android/pull/536 by @erisu with the comment:
When platform is installed though CLI, cordova platform add android, the copy node_modules step is no longer valid as dependencies are now at the project level.
The step is required only when the create binary from the platform repo is called.
I was using the CLI to add the platform (C:\Projects\cordova5\cordova-cli\bin\cordova platform add "C:\Projects\cordova5\cordova-android" --verbose
), so something went wrong there I guess :/
Further discussion on how to solve the underlying CLI/Android problem is moved here: https://github.com/apache/cordova-cli/issues/362#issuecomment-443547612
@janpio thanks for the info Jan. As you said, it works fine for browser platform. I guess we can close this once https://github.com/apache/cordova-cli/issues/362 is sorted out. Please correct me if I m wrong
Yep, https://github.com/apache/cordova-cli/issues/362 and https://github.com/apache/cordova-cli/issues/363 have to be fixed for this to work again. The second one is Windows only I think.