Local installation


#1

hi all,

i am running 3 nodejs based applications in one single machine. one for admin website, another for web api, another ionic3 app. All are written in different node npm versions. Hence I cant install ionic globally with -g option which is recommended in official tutorial.

for that reason i use nvm and install older versions locally for admin website and api, both build and run fine.

but ionic commands give build error. first i used to get “ionic - command not found”, then i tried using $(npm bin)/ionic --version, i started getting responses. But commands for building android apk etc fail. in another machine i have ionic installed globally, those commands work fine and i am able to generate apk.

in summary, how to install ionic locally and execute ios and android builds locally ?


#2

Hi,

I had to do this in the past.
You have to add ionic and cordova as devDependencies in your package json (don’t forget npm install). and create yours custom commands :

"scripts": {
    "ionic": "ionic"
}

then use :

npm run ionic cordova build android

#3

If you’ve already got nvm installed, you should be set. You should be able to install ionic CLI with -g. I’ve used that setup for years.


#4

My requirement is not to install using -g


#5

thanks, does this mean i need to copy these texts into package.json and execute npm install

and then my command for npm run ionic cordova build android will work ?

your text does not have a cordova mentioned ! can i see a working example of a package.json ?


#6

In your package.json add in the “devDependencies” field this lines (with the versions you want) :

"devDependencies": {
    "cordova": "7.1.0",
    "ionic": "4.0.3"

then add in “scripts” field

"scripts": {
    "ionic": "ionic"
}
npm install 

Then you can use all commands you want in the versions you want

npm run ionic cordova build android
npm run ionic cordova build ios
npm run ionic serve

#7

I don’t understand why. nvm effectively gives you a dedicated entire node ecosystem at whatever granularity you please, in which -g means “only in this sandbox I use for this particular purpose”.


#8

Thanks … but still there is a problem. i might have npm version which may mismatch with ionic cordova version i am mentioning here ! isn’t it ? I am using cordova 7.0.0 and ionic 3.19.0


#9

npm install

npm WARN deprecated @ionic/cli-utils@1.19.0: Latest Ionic CLI does not use this package.

npm WARN deprecated node-uuid@1.4.8: Use uuid module instead

npm WARN deprecated hoek@2.16.3: The major version is no longer supported. Please update to 4.x or newer

npm ERR! code Z_BUF_ERROR

npm ERR! errno -5

npm ERR! zlib: unexpected end of file

npm ERR! A complete log of this run can be found in:

npm ERR! /Users/rashmikandakur/.npm/_logs/2018-10-12T10_13_44_726Z-debug.log

i get this error

my package.json looks like below

{
“devDependencies”: {
“cordova”: “7.0.0”,
“ionic”: “3.19.0”
},
“scripts”: {
“ionic”: “ionic”
}
}

node version is 8.9.4
npm version is 6.3.0


#10

Is your package.json have only this ???

{
“devDependencies”: {
“cordova”: “7.0.0”,
“ionic”: “3.19.0”
},
“scripts”: {
“ionic”: “ionic”
}
}

I gave you only the things to append to your own package.json. Here you can see a full working package.json. You have to replace the packages and versions with YOUR needs.

{
  "name": "myApp",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "config": {},
  "scripts": {
    "ionic": "ionic"
  },
  "dependencies": {
    "@angular-devkit/core": "0.0.29",
    "@angular-devkit/schematics": "0.0.34",
    "@angular/common": "4.4.3",
    "@angular/compiler": "4.4.3",
    "@angular/compiler-cli": "4.4.3",
    "@angular/core": "4.4.3",
    "@angular/forms": "4.4.3",
    "@angular/http": "4.4.3",
    "@angular/platform-browser": "4.4.3",
    "@angular/platform-browser-dynamic": "4.4.3",
    "cordova-android": "~6.3.0",
    "cordova-browser": "~5.0.3",
    "cordova-ios": "~4.5.4",
    "es6-promise-plugin": "^4.2.2",
    "ionic-angular": "3.7.1",
    "ionicons": "3.0.0",
    "rxjs": "5.4.3",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.7",
    "@types/async": "2.0.42",
    "@types/node": "7.0.5",
    "cordova": "7.1.0",
    "ionic": "4.0.3",
    "ts-node": "3.3.0",
    "typescript": "2.3.4",
    "webpack": "3.1.0",
    "xmldom": "0.1.27"
  },
  "description": "An Ionic project",
  "cordova": {
    "platforms": [
      "android",
      "ios",
      "browser"
    ]
  }
}

Then npm install will work. Using old versions will cause deprecations warnings. It’s normal.

If you have to use different version of npm/node you can use nvm as @rapropos said :


#11

Thank you sir. bit of a nodejs novice. hence some stupid questions . my point is, i need to use ionic 3.19.0 [that is my project requirement] cordova 7.0.0 [though cordova claims, thers is no version dependency with ionic version] can there be some clashes with other packages mentioned here ? how to figure out a mapping i will change ionic to 3.19.0 and cordova to 7.0.0 and see if it worked


#12

I think you already had a project with a package.json. In which case it was enough to add the fields I gave you.

If it’s not the case. You must identify all dependencies that your application uses.

Angular,
Ionic,
Cordova,
ionic-angular … etc

You can get inspired by a package.json by starting an new ionic application created with your own ionic version.

To know the dependencies of a package you can use:
npm info yourPackageName peerDependencies

For example:

npm info @angular/core peerDependencies

Return :
{rxjs: '^ 6.0.0', 'zone.js': '~ 0.8.26'}

Then to use @angular/core package i have to add rxjs and zone.js in my dependencies too.

When you run npm install if you made a mistakewith your package and versions, npm will return an error and suggest you what to do.