Cordova - Current working directory is not a Cordova-based project
Asked Answered
G

16

52

I'm using phonegap for my mobile project. My question is why I got this error when I try to search phonegap plugin using cordova CLI? I run this command in terminal to search phonegap plugin

cordova plugin search bar code

Full error message

Last login: Wed Jan 22 15:04:09 on ttys000
Mohammads-MacBook-Pro:~ mohammadnurdin$ cd /Applications/MAMP/htdocs/rmbp/apps/rmbp/iphone/native
Mohammads-MacBook-Pro:native mohammadnurdin$ cordova plugin search bar code

/usr/local/lib/node_modules/cordova/src/util.js:57
            throw new Error('Current working directory is not a Cordova-based 
                  ^
Error: Current working directory is not a Cordova-based project.
    at Object.module.exports.cdProjectRoot (/usr/local/lib/node_modules/cordova/src/util.js:57:19)
    at CLI.plugin (/usr/local/lib/node_modules/cordova/src/plugin.js:28:36)
    at new CLI (/usr/local/lib/node_modules/cordova/src/cli.js:109:30)
    at Object.<anonymous> (/usr/local/lib/node_modules/cordova/bin/cordova:41:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
Mohammads-MacBook-Pro:native mohammadnurdin$ 
Guthrie answered 22/1, 2014 at 7:3 Comment(0)
C
4

You have to be in a project before you launch cordova plugin search bar code.

Canyon answered 22/1, 2014 at 9:3 Comment(1)
how to that? can u give me a scenario?Guthrie
T
78

If you are getting this error on Ionic2
This issue generally occur when we just clone / download app and try to add platform to it.

its very easy to resolve, then here are the steps-

just create a "www" directory in application root.

"./www"

can also do by this command-

mkdir www

now we can easily run following command -

ionic platform add android
or
ionic platform add ios

Hope it will help!!!

Tenebrae answered 22/3, 2017 at 12:25 Comment(0)
S
59

Solution is to make sure there's a www/ directory inside the root directory.

mkdir www

make sure your .gitignore file doesn't include www/ directory on it.

Saponify answered 2/5, 2018 at 6:26 Comment(2)
Yes, someone put www/ into gitignore and this fixed it.Belenbelesprit
A custom script that I use to deploy my app was accidentally moving the www directory out of the project root. This answer helped me notice the missing folder.Kemper
B
26

Yes, as QuickFix said, you need to be in a Cordova project before being able to use most of cordova Commands. If you are curious about what defines a Cordova project, this is what I found:

  • Has a .cordova directory, with a config.json inside.
  • Has a www directory, with a config.xml inside.
  • Has a platforms directory.

With that in place you can use Cordoba commands without problem. If you need examples of those config files just run cordova create myapp.

Breakfast answered 18/4, 2014 at 10:43 Comment(0)
C
11

Happened to me also, probably from npm/node updates.

Worked for me the following:

npm install -g cordova

ionic cordova platform list

Cowberry answered 21/1, 2020 at 8:43 Comment(0)
C
4

You have to be in a project before you launch cordova plugin search bar code.

Canyon answered 22/1, 2014 at 9:3 Comment(1)
how to that? can u give me a scenario?Guthrie
F
1

Create www folder on root directory. If still it's a issue check ionic info and try to upgrade

Fabulous answered 31/1, 2018 at 11:28 Comment(0)
D
1
  1. run ionic serve
  2. It will create www folder
  3. Then run cordova prepare
Disembarrass answered 29/9, 2018 at 13:18 Comment(0)
M
1
ionic integrations enable --add

then run the

ionic build

it will add all the necessary files

Mozzarella answered 25/10, 2019 at 5:25 Comment(0)
H
1

I also had the same problem. i had an angular project. then created a cordova app inside called mobile

cordova create mobile

Then i tried to run

cordova platform add android

Which gave me the same error 'Current working directory is not a Cordova-based project'.

Solution : i have to go to the mobile folder ( from the command prompt cd mobile ) then i had to run the command there. Also there had to be a www folder in that mobile folder

Horsefaced answered 6/11, 2019 at 19:54 Comment(0)
V
0

Did you come here because your Azure DevOps (fka VSO/VSTS) Cordova build pipe task failed with "Current working directory is not a Cordova-based project"?

Resolved by creating the required (and missing) folder 'www\', with a powershell having script:

New-Item -ItemType directory -Path www\

Veilleux answered 29/11, 2018 at 16:21 Comment(0)
R
0

Once you create a new project using the create command,you need to change the directory to the newly create project where you are going to build your app.

eg. E:\Andriod\myapp>cordova create newapp Creating a new cordova project.

E:\Andriod\myapp>cordova build Current working directory is not a Cordova-based project.

E:\Andriod\myapp>cd newapp

E:\Andriod\myapp\newapp>cordova build

it will be working at this point

Romilda answered 3/3, 2019 at 13:31 Comment(0)
C
0

This may be silly but in my case it was the config.xml file.

I usually create it dynamically using a script, therefor it wasn't there after I cloned the repo. Ran the script to re-create it and everything worked again.

Cand answered 23/4, 2020 at 8:9 Comment(0)
T
0

Use

ionic cordova build [platform]
ex. ionic cordova build android
or for ios 
ionic cordova build ios

It will automatically create the www folder path. see more commands here https://ionicframework.com/docs/cli/commands/cordova-build

[Note: Make sure you install ionic and cordova

npm install -g ionic
npm install -g cordova
Tice answered 9/8, 2021 at 4:4 Comment(0)
J
-1

I cannot explain the source of the error, but in case you are looking for a solution, you might want to try plugman instead.

Jhansi answered 7/2, 2014 at 10:29 Comment(0)
A
-1

THis Solution helped me: go to Root of your Project via cmd and run.

npm run build-cordova

after that just create new android platforms

cordova platform rm android cordova platform add android

Anthropomorphosis answered 17/8, 2021 at 19:12 Comment(0)
S
-2

you have to be in the current project in command prompt(example project name is myapp).

example screen shot

Shalne answered 20/8, 2017 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.