2
votes

I'm attempting to deploy a nodeJS app on AWS CodeDeploy, and have an issue with gulp dependencies and running npm install/start from a bash file.

I have a standard app folder structure, with package.json in the project root etc.

Bash file (bin/npm_install.sh)

cd /opt/deployments/app-backend
npm install

NPM script definitions

"scripts": {
  "postinstall": "gulp minify-sdk && gulp setup-auto",
  "start": "gulp",
  "test": "gulp test"
}

Error when running bin/npm_install.sh

[stdout]
[stdout]> [email protected] start /opt/deployments/app-backend
[stdout]> gulp
[stdout]
[stderr]
[stderr]module.js:340
[stderr]    throw err;
[stderr]          ^
[stderr]Error: Cannot find module 'pretty-hrtime'
[stderr]    at Function.Module._resolveFilename (module.js:338:15)
[stderr]    at Function.Module._load (module.js:280:25)
[stderr]    at Module.require (module.js:364:17)
[stderr]    at require (module.js:380:17)
[stderr]    at Object.<anonymous> (/opt/deployments/app-backend/node_modules/.bin/gulp:5:18)
[stderr]    at Module._compile (module.js:456:26)
[stderr]    at Object.Module._extensions..js (module.js:474:10)
[stderr]    at Module.load (module.js:356:32)
[stderr]    at Function.Module._load (module.js:312:12)
[stderr]    at Function.Module.runMain (module.js:497:10)
[stderr]npm ERR! weird error 8
[stderr]npm WARN This failure might be due to the use of legacy binary "node"
[stderr]npm WARN For further explanations, please read
[stderr]/usr/share/doc/nodejs/README.Debian
[stderr] 
[stderr]npm ERR! not ok code 0

NOTE: Running npm install works fine from the project root folder.

Any suggestions? Is this the best way to start the app after codedeploy has finished deploying the code?

2

2 Answers

0
votes

You can use 'AfterInstall' lifecycle event to install your modules and use 'ApplicationStart' lifecycle event to start the app. Does manually running npm_install.sh succeed?

0
votes

Whilst I haven't discovered an explanation for this, the issue was that when the node_modules folder was being returned from TravisCI/CodeShip, the node_modules/.bin/* files did not have symlinks so those modules could not resolve their internal dependencies.

I ended up resolving this by running npm install gulp in the after_install hook which recreated the symlinks.