Building ionic on vagrant through php exec

Yes me too. However at this stage I think it is think it is having two versions of node on there. I will try to sort this first which is also proving to be a pain then worry about the sim links later.

So I updated my vagrant box now using node v6.11.1

Did a npm install.

Installed Ionic globally.

Then got sh: 1: ionic: not found when running ionic info

Running how?

npm list -g --depth=0 lists the installed packages.

├── cordova@7.0.1
├── ionic@3.7.0
└── jshint@2.9.5

that is ssh

in shell_exec i get

/home/vagrant/.npm-global/lib
+-- cordova@7.0.1
+-- ionic@3.7.0
`-- jshint@2.9.5

I did follow option 2 on here https://docs.npmjs.com/getting-started/fixing-npm-permissions to change permissions if this makes any difference.

Sorry being silly forgot npm. It is working. I will see if the build now works.

Still get errors.

npm run ionic:build --verbose 2>&1;
npm verb lifecycle ionic-hello-world@~ionic:build: unsafe-perm in lifecycle true
npm verb lifecycle ionic-hello-world@~ionic:build: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/vagrant/Code/laravel/hybrid/node_modules/.bin:/usr/bin
npm verb lifecycle ionic-hello-world@~ionic:build: CWD: /home/vagrant/Code/laravel/hybrid
npm info lifecycle ionic-hello-world@~ionic:build: Failed to exec ionic:build script
npm verb stack Error: ionic-hello-world@ ionic:build: `ionic-app-scripts build`
npm verb stack spawn sh ENOENT
npm verb stack     at exports._errnoException (util.js:1018:11)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
npm verb stack     at onErrorNT (internal/child_process.js:367:16)
npm verb stack     at _combinedTickCallback (internal/process/next_tick.js:80:11)
npm verb stack     at process._tickCallback (internal/process/next_tick.js:104:9)
npm verb pkgid ionic-hello-world@
npm verb cwd /home/vagrant/Code/laravel/hybrid
npm ERR! Linux 4.4.0-81-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "ionic:build" "--verbose"
npm ERR! node v6.11.1
npm ERR! npm  v3.10.10
npm ERR! file sh
npm ERR! path sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn sh
npm ERR! ionic-hello-world@ ionic:build: `ionic-app-scripts build`
npm ERR! spawn sh ENOENT
npm ERR! 
npm ERR! Failed at the ionic-hello-world@ ionic:build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ionic-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.
npm verb exit [ 1, true ]
npm info lifecycle ionic-hello-world@~ionic:build: Failed to exec ionic:build script
npm verb stack Error: ionic-hello-world@ ionic:build: `ionic-app-scripts build`
npm verb stack Exit status -2
npm verb stack     at EventEmitter. (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
npm verb stack     at emitTwo (events.js:106:13)
npm verb stack     at EventEmitter.emit (events.js:191:7)
npm verb stack     at ChildProcess. (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
npm verb stack     at emitTwo (events.js:106:13)
npm verb stack     at ChildProcess.emit (events.js:191:7)
npm verb stack     at maybeClose (internal/child_process.js:891:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
npm verb stack     at onErrorNT (internal/child_process.js:367:16)
npm verb stack     at _combinedTickCallback (internal/process/next_tick.js:80:11)
npm verb pkgid ionic-hello-world@
npm verb cwd /home/vagrant/Code/laravel/hybrid
npm ERR! Linux 4.4.0-81-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "ionic:build" "--verbose"
npm ERR! node v6.11.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! ionic-hello-world@ ionic:build: `ionic-app-scripts build`
npm ERR! Exit status -2
npm ERR! 
npm ERR! Failed at the ionic-hello-world@ ionic:build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ionic-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.
npm verb exit [ 1, true ]

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/Code/laravel/hybrid/npm-debug.log

Well, that’s the same as where we started, right?

Does ionic info work now via the script?

It ended up being a permissions thing.

I had to globally install ionic.

Change permissions on node and the following folders

sudo chown -R vagrant /usr/local
sudo chown -R vagrant /usr/lib/node_modules
sudo chown -R vagrant /usr/bin

Then it worked. Sim links were created ok by the installers if I did npm install on vagrant after deleting node modules.

However don’t think I can build on my local machine now.

But I can live with this.

1 Like

The advice given in the previous post is IMHO completely crazy. You have effectively made the vagrant user a superuser, completely eliminating the point of having it exist as a separate user in the first place. Completely reinstalling the OS is the only way to fix such damage. Please, please, nobody follow or spread this extremely foolish advice.

Yeah you might have a point there actually. Well its a good job it is on vagrant as rebuilding the whole OS is easy and its not live. But it suggests where the problem lies.

If the problem is installing global npm packages as “vagrant”, I would look into installing nvm as that user. That way, everything will go in /home/vagrant/.nvm (or underneath whatever their home directory is), and you shouldn’t have to chown anything.

I think I tried something like this see link above.

Node was working fine. It was only the Ionic cli which seem to not have permission.

If node is being managed under nvm, I can’t think of any reason ionic CLI would need write access to anything outside of (a) the project directory, (b) $HOME/.nvm, or (c) /tmp, all of which should be writeable by whatever user is invoking it.

That looks cool actually, just seen this

Will try again tomorrow!

Right so I rebuilt the vagrant box.

Installed nvm.

Installed node through nvm in vagrant.

Switched to use latest node 8.3.0.

The script is still using 6.11.2

What am I missing? It’s getting late. :slight_smile:

When I say the script i mean the shell_exec.

Perhaps not switching with nvm use. Each separate shell/terminal can have a separate idea of which node to use. You can see if this is the case by checking printenv | grep -i nvm and seeing if PATH and NVM_BIN look sane at the time your script is executing.

I did nvm use in the terminal but the script is still using the other node. I tried putting nvm use to no avail also.

Is there any easy way the script can tell you what its environment variables are?

I am not sure what you mean by that.

I hate PHP, so I would be doing this via a shell script instead. In a shell script, you can just put printenv in the script and it will spit out the entirety of all environment variables that the script is seeing. I assume there must be something similar in PHP, but I don’t know what it is.