Fail to deploy node.js application to heroku - node.js

I am trying to deploy a simple node.js express-based application to heroku, something which is apparently very basic: https://devcenter.heroku.com/articles/nodejs
Here is my package.json:
{
"name": "cours-lic3-blois",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "*",
"ejs": "*",
"github-flavored-markdown": "*",
"less-middleware": "*"
},
"engines": {
"node": "0.8.8",
"npm": "1.1.65"
}
}
When I git push heroku master I got the following trace:
-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.8.8
Using npm version: 1.1.65
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
npm ERR! Error: ENOENT, chmod '/tmp/build_1suuxlhd9s8n6/node_modules/express/bin/express'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 2.6.32-348-ec2
npm ERR! command "/tmp/node-node-tonf/bin/node" "/tmp/node-npm-NG88/cli.js" "rebuild"
npm ERR! cwd /tmp/build_1suuxlhd9s8n6
npm ERR! node -v v0.8.8
npm ERR! npm -v 1.1.65
npm ERR! path /tmp/build_1suuxlhd9s8n6/node_modules/express/bin/express
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/build_1suuxlhd9s8n6/npm-debug.log
npm ERR! not ok code 0
! Failed to rebuild dependencies with npm
! Heroku push rejected, failed to compile Node.js app
To git#heroku.com:fast-everglades-2007.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:fast-everglades-2007.git'
I tried to tweak various versions in my package.json but to no avail. I am developing on windows and it might be possible this ENOENT issue is due to some filemode issue.

I got this fixed by:
Making sure Procfile is committed into git
Removing the node_modules/ folder and committing that into git (git rm -r node_modules/)
Afterwards, I did the git push heroku master then the error disappeared.

I had this problem, and it was because:
I keep node_modules in version control
I had bin in my .gitignore file
npm was attempting to chmod express/bin/express, but due to my .gitignore this file wasn't in git and thus was not being cloned during the deploy, so it failed. I didn't notice it because a local npm install would create the bin/express file as usual.
Removing bin from .gitignore and committing the missing files solved the problem for me.

Heroku team, could you please consider configuring npm to use npm install --no-bin-links --production by default, or creating an environment variable to let users set that flag. This is a serious bug in node installs. Removing the bin directory from my .gitignore (as suggested below) enabled me to deploy, but it breaks using git effectively in a cross-platform development environment, requiring an explicit npm rebuild on every git pull where node_modules might have changed.
NPM best practice is to avoid having node_modules in .gitignore (see http://www.futurealoof.com/posts/nodemodules-in-git.html ).
I believe --no-bin-links will provide the best of both worlds, enabling deploys of node_modules where the bin directory has been excluded, supporting npm rebuild, but not failing when a bin link is created.
I submitted a pull request here: https://github.com/heroku/heroku-buildpack-nodejs/pull/33
Thanks!

similar issue was fixed by renaming gruntfile.js to Gruntfile.js

I had a similar problem a few days ago, I think it was because I imported a module created by me and that was what gave the error;
I corrected it like this:
I called the module "path"
const path = require ("path")
and then where my module was imported I made a join of the file path
const myModule = require (path.join (__ dirname, 'MyModule.js'))

Related

Heroku failed to push

I want to deploy my project on Heroku but when I do it, I have this error :
npm ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR!
npm ERR!
npm ERR! Invalid: lock file's fs#0.0.1-security does not satisfy fs#*
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.3oo5n/_logs/2021-11-25T14_47_03_365Z-debug.log
-----> Build failed
Even when I delete "package-lock.json" and make "npm install", it still doesn't work.
This is the first time that I have this problem with Heroku deployment, I don't know what can I do about it.
Thank you for your help.
I was having the same issue and it was working at first then it stopped. Deleting the packages-lock.json file and then re-running npm install wasn't working. Strangely it did work if I just removed packages-lock.json but that wasn't the ideal solution.
Finally, I did get it to work by following:
delete my packages-lock.json file
delete node_modules
re-run npm install

Installing git through .ebextensions on Elastic Beanstalk

I'm getting an error deploying to Elastic Beanstalk, because there is no git on the instance. One of the dependencies in my package.json is dependant on a git repository and needs to git clone.
Git is not installed on the instances. I tried installing it through .ebextensions .conf file while deploying, through yum, but when I ssh into the instance it's not there.
Question is: what is the correct way to install and have git on a Linux instance running on Elastic Beanstalk before npm install is called on that instance?
Here's the log showing the error:
[2015-04-18T09:00:02.815Z] ERROR [1777] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
caused by: + /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN package.json amity-api-v2#2.0.0 No repository field.
npm WARN package.json amity-api-v2#2.0.0 No README data
npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined
npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined
npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined
npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined
npm ERR! Linux 3.14.35-28.38.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/npm" "--production" "install"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ENOGIT
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.
If you put a config file in your .ebextensions folder like this:
packages:
yum:
git: []
Make sure the git package is in a config file with a higher execution index then one that actually requires git. It is common to have it in a first config file named: 00-packages.config.
I can think of three ways you could ensure git(or any dependency) is installed on the system before npm install is run.
Define a preinstall script in your package.json that installs git if required.
You can add a script(file), using ebextensions in either the pre-appdeploy hooks directory, or the preinit hooks directory. I would suggest the preinit hook, as that's where the hook for installing packages is. Just set the path of your script to /opt/ebextensions/hooks/preinit/99_install_git.sh, or if you want to do in pre-appdeploy, /opt/ebextensions/hooks/appdeploy/pre/99_install_git.sh, and make the file executable by using the mode field.
Using ebextensions to install a package.
For your use case, I think #3 is the best option. Kinda late, but I hope you find it useful

Installing Node.js modules from file system on Azure Websites

I have a Node.js app running as an Azure Website and doing my deployments using Git. The app requires a module that's private (i.e. written by me, no relevance to anyone else and thus not available in NPM) and common to my other projects. Let's say the module is located in ./lib/mymodule and it has its own dependencies in its package.json file. The problem is I cannot figure out how to have Azure install the dependencies of my own module. I would like to avoid having to add my node_modules directory under version control (currently .gitignor'd) or having to add the module's dependencies as my app's dependencies (which is ugly and a bit inconvenient).
It's trivial to get this working on my local dev environment. The first thing I did was simply include my own module as a local dependency in my package.json as described in https://docs.npmjs.com/files/package.json (see section "Local Paths"). A simple npm install would now install my own module nice and easy. Since I know that Azure runs npm install every time I deploy a new version, I figured this is all I need. Turns out I was wrong: local paths in package.json dependencies section were only introduced in NPM 2.0.0 and Azure is running NPM 1.4.x, so the deployment obviously failed. Ok then, can I run a different version of NPM in Azure? In theory, yes, but practice seems to be something else. I tried out https://github.com/glennblock/azure-node-runtime-selector but to no avail. Here's some of the deployment output:
remote: Handling node.js deployment.
remote: KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
remote: ............
remote: node version: 0.11.14
remote: ..............
remote: 2.1.18
remote: npm version: 1.4.6
remote: An error has occured during web site deployment.
remote: npm failed
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
Apparently it fails to install any NPM version >= 2.0.0.
Ok then, this is not so bad, I figured. I can work with an older version of NPM, I just need to run another npm install to install my own module, as NPM documentation hints. So I took the local dependency away from my package.json and simply run npm install ./lib/mymodule. Nice and easy... on my local. I dug up instructions how to run custom commands on deployment in Azure: just run azure site deploymentscript --node and edit deploy.sh it creates. Just to ensure the custom deployment script works at all, I made one deployment without editing anything. Worked ok. Then I added a line in deploy.sh (around line 111):
# 3. Install npm packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
eval $NPM_CMD install --production
eval $NPM_CMD install ./lib/mymodule #This line added by me
exitWithMessageOnError "npm failed"
cd - > /dev/null
fi
Nope. This is what I get:
remote: Installing npm packages...
remote: npm ERR! addLocal Could not install ./lib/mymodule
remote: An error has occurred during web site deployment.
remote: npm ERR! Error: ENOENT, stat 'd:\home\site\wwwroot\lib\mymodule'
remote: npm failed
...snip...
remote:
remote: npm ERR! System Windows_NT 6.2.9200
remote: npm ERR! command "d:\\Program Files (x86)\\nodejs\\0.10.28\\node.exe" "D:\\Program Files(x86)\\npm\\1.4.9\\node_modules\\npm\\bin\\npm-cli.js" "install" "./lib/mymodule"
remote: npm ERR! cwd d:\home\site\wwwroot
remote: npm ERR! node -v v0.10.28
remote: npm ERR! npm -v 1.4.9
remote: npm ERR! path d:\home\site\wwwroot\lib\mymodule
remote: npm ERR! code ENOENT
remote: npm ERR! errno 34
remote: npm
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
This is where I got stuck. I tried playing around with the path, guessing that Windows is mangling it somehow, but haven't found a working solution yet. The weird thing is that ./lib/mymodule would seem to resolve to d:\home\site\wwwroot\lib\mymodule which look just fine to me and DOES exist, at least after deployment when I FTP'd in to take a look.
I would appreciate any and all help in either getting NPM 2.x.x working or my making custom deployment go through. Or maybe there's an alternative to managing my local modules I haven't thought of? And if all else fails, maybe I'll just commit my node_modules or manage my dependencies manually. I've already used way too much time to resolve what first seemed like a trivial issue. :)
Azure WebSites team will be shipping support for npm 2.1.17 out-of-the box by end of the month (Jan'15). Hope this will help you unblock you.

Trouble with first Node app deployment through Heroku

Having followed the 12devs of Xmas tutorial to create my first Node.js app (http://12devsofxmas.co.uk/post/2012-12-28-day-3-realtime-collaborative-drawing-with-nodejs) I'm now attempting to follow Rob Dodson's tutorial for deploying it through Heroku (http://robdodson.me/blog/2012/06/04/deploying-your-first-node-dot-js-and-socket-dot-io-app-to-heroku/)
However, after committing to github, when I attempt to push to Heroku, I get the following error output:
-----> Installing dependencies with npm
npm WARN package.json Draw#0.0.1 No README.md file found!
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-2.5.11.tgz
npm http 200 https://registry.npmjs.org/express/-/express-2.5.11.tgz
npm ERR! Refusing to delete: /tmp/build_1t6d7hbd2psal/node_modules/.bin/express not in /tmp/build_1t6d7hbd2psal/node_modules/express
File exists: /tmp/build_1t6d7hbd2psal/node_modules/.bin/express
Move it away, and try again.
npm ERR! System Linux 2.6.32-350-ec2
npm ERR! command "/tmp/node-node-Fenl/bin/node" "/tmp/node-npm-6pyT/cli.js" "install" "--production"
npm ERR! cwd /tmp/build_1t6d7hbd2psal
npm ERR! node -v v0.6.20
npm ERR! npm -v 1.1.65
npm ERR! path /tmp/build_1t6d7hbd2psal/node_modules/.bin/express
npm ERR! code EEXIST
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/build_1t6d7hbd2psal/npm-debug.log
npm ERR! not ok code undefined
npm ERR! not ok code 1
! Failed to install --production dependencies with npm
! Heroku push rejected, failed to compile Node.js app
To git#heroku.com:secure-dawn-2437.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:secure-dawn-2437.git'
My package.json file is as follows:
{
"name": "Draw",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "~2.x",
"socket.io": "~0.9.x"
},
"engines": {
"node": "0.6.x",
"npm": "1.1.x"
}
}
I'm sorry - I'm totally new to this sort of development, having mostly worked in Java while in school, but I'm anxious to learn. I assume the problem is somehow with express, but I'm not sure what it means by "move it away, and try again."
Do you have a Procfile file in your application you are trying to deploy?
If not, look at the documentation available on Heroku's Website:
https://devcenter.heroku.com/articles/nodejs#declare-process-types-with-procfile
EDIT:
I highly suggest you to deploy a really simple Node.js application at first (like a Hello World), just so you can trace back the source of your error.
Try removing bin and .bin from your .gitignore or adding node_modules to .gitignore. More info here: Fail to deploy node.js application to heroku
I was able to solve this by temporarily disabling Heroku's use of cache:
heroku config:set NODE_MODULES_CACHE=false
Push the build, then turn cache back on.

Error deploying node js restify application to heroku

I'm having an issue deploying a restify application to Heroku.
npm ERR! dtrace-provider#0.0.9 install: `node-waf clean ; node-waf configure build`
npm ERR! `sh "-c" "node-waf clean ; node-waf configure build"` failed with 1
npm ERR!
npm ERR! Failed at the dtrace-provider#0.0.9 install script.
npm ERR! This is most likely a problem with the dtrace-provider package,
npm ERR! not with npm itself.
It seems as if Heroku has an issue with dtrace, which restify makes use of, although doesn't require, I've read that you can bypass this by removing dtrace from restify's package.json file, however I have attempted this with no success.
I'm new to node and using Heroku and git so I'm sure there's something I'm missing, restify's package.json file contains the following:
"dependencies": {
"dtrace-provider": "0.0.9",
},
"optionalDependencies": {
"dtrace-provider": "0.0.9"
},
I have removed these lines but still receive the same error message as above after committing to git and pushing to Heroku.
Can anyone see what I'm missing?
When you deploy your application on heroku it installs the dependencies based on your application package.json file so it does not matter if you remove it from restify's package.json file because heroku picks the restify's package.json file from it's repository not from your repository. So, you need to find out how to resolve this error.

Resources