AWS Elastic Beanstalk Node.js npm install error - node.js

During the deployment of an application, npm install is unable to install a very particular dependency:
npm ERR! enoent ENOENT: no such file or directory, chmod '/tmp/deployment/application/node_modules/babel-core/node_modules/regexpu/node_modules/regjsparser/node_modules/jsesc/bin/jsesc'
I was able to find that above error by ssh'ing into the particular EC2 instance hosting my Node application and running npm install via the command below:
sudo /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install 2
Then follows with this generic failure:
Failed to run npm install. Snapshot logs for more details.
No environment variable EB_EVENT_FILE found. Writing message to stderr.
Msg: Failed to run npm install. Snapshot logs for more details.
What's weird is that I've been able to deploy successfully once before, and am using the same exact configurations for that previous deployment. My only command is npm start within .ebextensions/.
Within my package.json, I changed all dev dependencies into dependencies, as webpack is building during prestart.
This all builds and runs locally, by the way. Also I'm using Node 4.2.1 and npm 2.14.7 on EB.
Any help would be awesome. Thanks!

I ended up just creating and deploying a Docker container to solve this issue. Deploying to the environment provided by EB is too nondeterministic - the dependency tree wasn't created correctly.

Related

Stop EBS Linux 2 (Node.js) from trying to do npm install?

I'm trying to run a Node application on AWS Linux 2 on Elastic Beanstalk and need to install the dependencies using yarn. (My Node app causes errors if you try to use npm to install dependencies instead of yarn.)
I've already figured out how to set up a script in .platform/hooks/prebuild/ to get it to run yarn, but even though it's running the yarn installation, it still also tries to run npm install, which errors out, causing my deploy to fail.
So I need to figure out how to prevent the default npm install step from running.
(Does anyone know what file that command is run from in the AWS Linux 2 setup process? I was wondering if I could just add another script in .platform/hooks/prebuild/ that would modify that file to prevent the call to npm.)
yes, you can avoid npm install
When you deploy a node_modules directory to an Amazon Linux 2 Node.js platform version, Elastic Beanstalk assumes that you're providing your own dependency packages, and avoids installing dependencies specified in a package.json file.
source doc

Error while using create-react-app - ENOENT

New Node & React user here. I'm following the React tutorial but run into a problem on my Windows 10 machine:
C:\Users\Wout>create-react-app my-app
Creating a new React app in C:\Users\Wout\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! path C:\Users\Wout\my-app\node_modules\abab
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Wout\my-app\node_modules\abab' -> 'C:\Users\Wout\my-app\node_modules\.abab.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Wout\AppData\Roaming\npm-cache\_logs\2018-03-14T15_21_11_867Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-app / from C:\Users\Wout
Done.
Things I've tried so far:
Reinstall Node.js (v8.10.0, npm 5.6.0)
Disabling Adobe creative cloud sync & related processes (these were spawning node.exe processes)
Running CMD in admin
Run the command from VS Code Powershell
Closing Visual Studio Code before executing the command
Run the command with npx
Rebooted the system several times
Running the command from the user folder as well as other drives
Running the Typescript version: create-react-app my-app --scripts-version=react-scripts-ts
It's all quite strange to me, since on Mac OS X the command executes without issues. I also can't seem to find other people with the same problem.
For what it's worth, it always stops after this "finalizing abab" package step.
I have an installation of XAMPP running an Apache and MySQL service, don't know if that has anything to do with it. I don't think so since I'm not even running the app yet, plus the server runs on port 3000 anyway.
I eventually solved it by closing as many extra processes as possible. Will try to find out which process was interfering with the command.
Edit: Ding ding ding! It was MalwareBytes! The "realtime protection 30-day trial" had restarted after an update and it was screwing with the filesystem.
I also just installed MalWareBytes, and I get the same error. I tried running create-react-app from the CLI as administrator, and while it was running I read your solution, and so I shut down MalWareBytes as the installation was in progress.
It worked, but I don't know if that is because I ran as administrator, or because I shut down MalWareBytes.
But for anyone having this problem, you could also try running your command prompt/powershell with administrator rights.
try running the command from the project directory...
worked for me.
i ran the command from the parent of the project directory for example:
reactApp/hellowworld
run from helloworle directory instead...
In case you have just install the create-react-app command , try to run the command from a new terminal . (re-open another tab).

'npm EER! code 1' When installing dependencies using `npm install --production`

I am using flightplan to deploy my node.js application to my server. I run the command fly production in my CLI to deploy my app to the server. It does rsync fine, but when it comes to installing dependencies, I get the following error:
I made sure that I have sudo privileges on my server for this user and npm is definitely installed as it gives the version number when I run the command npm -von my server. I have tried to run npm install --production myself on the server as the deploy script does and I get the same error, meaning it is something to do with installing dependencies. Potentially, it could be because in my flightplan.js, when it runs the command git ls-files to get the files to copy across. it includes all the node_modules even though i've made sure that node_modules is in the .gitingore file.
Does anyone have experience with flightplan npm module/or know why my npm install isn't working on my server?
(I edited out my server IP address from the picture)
Thanks in advance!
I found that if I removed the node_modules folder by running command rm -rf node_modules/ then committed this to github, then re-ran npm install and then my call to fly production worked successfully.

Jenkins cannot run npm or pm2 by itself

So I have a Jenkins CI setup on an EC2 server. I have nodejs and npm installed. Weirdly, Jenkins can access them via the command line if I do something like:
sudo -u jenkins node -v
However, Jenkins cannot access them inside an actual build runtime, and I get the following errors:
npm: command not found
pm2: command not found
npm is definitely installed, and ec2-user/root users can access it. What PATH do I have to change so that Jenkins can access it too?
I think that if you use the nodejs plugin it will be easier to manage your node and npm in this box. Also, this plugin allows installing some global modules that possibly you will need to build your project:
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

What is the recommended way to handle node.js private module dependencies?

I am currently working on an node.js app that is deployed on Elastic Beanstalk. It has started to reference a private module that is hosted on github as a private repository. Locally if I put a reference to it in the dependency section of my package.json like the following it works fine. I can run nom install, it downloads the module and the app works without issue.
"ModuleName": "git+https://TOKEN:x-oauth-basic#github.com/OWNER/REPO_NAME.git"
However, when I try to deploy to Beanstalk it fails with the following error:
2014-04-04 00:14:09,188 [DEBUG] (1630 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_sets': ['Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild'], 'returncode': 1, 'events': [{'msg': 'Failed to run npm install. Snapshot logs for more details.', 'timestamp': 1396570449, 'severity': 'ERROR'}, {'msg': 'Failed to run npm install. npm http GET https://registry.npmjs.org/express\nnpm ERR! not found: git\nnpm ERR! \nnpm ERR! Failed using git.\nnpm ERR! This is most likely not a problem with npm itself.\nnpm ERR! Please check if you have git installed and in your PATH.\n\nnpm ERR! System Linux 3.4.73-64.112.amzn1.x86_64\nnpm ERR! command "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/npm" "install"\nnpm ERR! cwd /tmp/deployment/appli', 'timestamp': 1396570449, 'severity': 'ERROR'}], 'msg': 'Error occurred during build: Command hooks failed\n'}], 'api_version': '1.0'}
From what I can tell by reading that it appears that git is not installed on the default linux AMI that Beanstalk uses. My question is what is the best way to handle this. Currently I'm considering the following two options:
Either use an AMI that has git installed or force the installation somehow during boot.
Create a build process that packages all my node_modules prior to deploying to Beanstalk.
Do these two options make sense or should I be considering another option? Is there a recommended way to handle this with Elastic Beanstalk or in the node ecosystem in general?
You can make sure that git is installed on the machine by adding a config file in the .ebextensions folder. See http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
If you add a file called .ebextensions/packages.config which contains the following:
#extra yum packages
packages:
yum:
git: []
This will install git on the machine before installation of your application.

Resources