Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mobile-spec project creation fails with error "Cannot find module 'cordova-common'" #159

Open
gandhirajan opened this issue Nov 27, 2018 · 18 comments
Labels

Comments

@gandhirajan
Copy link

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

@janpio
Copy link
Member

janpio commented Nov 27, 2018

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?

@gandhirajan
Copy link
Author

@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'

@janpio
Copy link
Member

janpio commented Nov 27, 2018

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.

@gandhirajan
Copy link
Author

@janpio Hi Jan, following are the detailed steps I tried:

  1. Installed latest node version v10.14.0
  2. Created a new root folder named "cordova_src"
  3. Navigated to root folder and ran the command - "coho repo-update -g -r all"
  4. Navigated to 'cordova-cli' inside root folder and ran the command - "npm install"
  5. Navigated to 'cordova-common' inside root folder and ran the command - "npm install"
  6. Navigated to 'cordova-js' inside root folder and ran the command - "npm install"
  7. Navigated to 'cordova-android' inside root folder and ran the command - "npm install"
  8. Navigated to 'cordova-mobile-spec\createmobilespec' inside root folder and ran the command - "npm install"
  9. 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. (D:\Gandhi\Cordova\Cordova_Releases\cordova-common\src\ConfigParser\ConfigParser.js:20:10)"

when I run cordova -version command from root folder. Am i missing something in installation and setup?

@janpio
Copy link
Member

janpio commented Nov 29, 2018

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.

@gandhirajan
Copy link
Author

gandhirajan commented Dec 2, 2018

@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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 android@8.0.0-dev.
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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.)

@gandhirajan
Copy link
Author

gandhirajan commented Dec 2, 2018

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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 android@8.0.0-dev.
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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?

@gandhirajan gandhirajan reopened this Dec 2, 2018
@brodycj
Copy link

brodycj commented Dec 2, 2018

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?

@gandhirajan
Copy link
Author

@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?

@brodycj
Copy link

brodycj commented Dec 2, 2018 via email

@janpio
Copy link
Member

janpio commented Dec 2, 2018

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.

@janpio
Copy link
Member

janpio commented Dec 2, 2018

@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 ios@5.0.0-dev.
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 cordova-ios@5.0.0-dev
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
...

@janpio
Copy link
Member

janpio commented Dec 2, 2018

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.

@janpio
Copy link
Member

janpio commented Dec 2, 2018

Investigation where the error is coming from:

  1. 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 (cordova-lib@9.0.0-dev)
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 (cordova-lib@9.0.0-dev)
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 ios@5.0.0-dev.
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 cordova-ios@5.0.0-dev
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)
  1. Last output before error is iOS project created with cordova-ios@5.0.0-dev.
    Code for this lives at:
    https://github.com/apache/cordova-ios/blob/62ebfbd74aff11b9fa0ca26685ee0578ecd9150f/bin/lib/create.js#L255-L262
    ... which is the last call of createProject:
    https://github.com/apache/cordova-ios/blob/62ebfbd74aff11b9fa0ca26685ee0578ecd9150f/bin/lib/create.js#L198-L239
    ... which is called in createPlatform:
    https://github.com/apache/cordova-ios/blob/2cd93097ec5d5989bc758f15db75011829c84c2b/bin/templates/scripts/cordova/Api.js#L113-L135
  2. So we know what happens after that output:
    https://github.com/apache/cordova-ios/blob/2cd93097ec5d5989bc758f15db75011829c84c2b/bin/templates/scripts/cordova/Api.js#L124-L129
  3. 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.

  1. Yep, for cordova-android the first require in the file is cordova-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.

@janpio
Copy link
Member

janpio commented Dec 2, 2018

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 apache/cordova-android#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 :/

@janpio
Copy link
Member

janpio commented Dec 2, 2018

Further discussion on how to solve the underlying CLI/Android problem is moved here:
apache/cordova-cli#362 (comment)

@gandhirajan
Copy link
Author

@janpio thanks for the info Jan. As you said, it works fine for browser platform. I guess we can close this once apache/cordova-cli#362 is sorted out. Please correct me if I m wrong

@janpio
Copy link
Member

janpio commented Dec 8, 2018

Yep, apache/cordova-cli#362 and apache/cordova-cli#363 have to be fixed for this to work again. The second one is Windows only I think.

@janpio janpio added the bug label May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants