I need to create a docker container with node v6.10.3, but with the latest npm (currently v5.4.1) to use new npm features for local packages.
Such installation runs without any problem on my Mac, but when I try to create a docker image with such an installation, after updating npm, the npm tool gets broken and throws a bunch of errors about missing packages.
Here is the example of the Dockerfile, with which I can reproduce this issue (note that my real Dockerfile is more complex):
FROM ubuntu:xenial
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN npm i -g npm
RUN npm i -g lerna
When the build process gets to the line RUN npm i -g lerna it throws a bunch of errors like:
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Any other npm script would result in the same errors. Reinstalling all the packages on which npm depends, does not seem as a solution for me.
I have also tried to install node inside the container using nvm, but I got the same errors.
My docker version:
Docker version 17.06.2-ce, build cec0b72
What's wrong with this Dockerfile and what am I missing?
I have found a workaround for this issue, using yarn.
It looks weird, but it works:
FROM ubuntu:xenial
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN npm i -g yarn
RUN npm uninstall npm -g
RUN yarn global add npm
RUN npm i -g lerna
Still, it would be great if somebody can explain why the original solution did not work, and/or help find a better way to fix it.
Related
I am working in a project previously built. This project was built using Node and Grunt.
I have a Gruntfile.js in the root folder of the project.
I installed grunt both locally and global, using
npm i grunt
npm i -g grunt
After, I installed grunt-cli both locally and global, using
npm i grunt-cli
npm i -g grunt-cli
And when I try to run any grunt command (develop, init, etc), I get the error
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'findup-sync'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/lib/nodejs/grunt-cli/bin/grunt:8:14)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
I searched in many forums and here too, but I haven't found an answer.
Can anybody help me?
UPDATE
After lose more than 24 hours working on this error, I fixed it with the following steps:
Install node-grunt-cli in Ubuntu via apt, like CPBL says in his comment
apt install node-grunt-cli
On OSX this wasn't necessary.
Following the steps I found on this blog. However, I also needed to run the command
grunt develop
as a sudo, even though changing the permissions of many folders.
Thanks to Pablo Lopes for putting me on the right track (see his question which includes the answer). I resolved my issue by:
Installing node-grunt-cli via apt:
sudo apt install node-grunt-cli
Running grunt with sudo:
sudo grunt
This isn't an ideal fix because it requires using sudo when running grunt - which shouldn't be necessary.
For me, installing via apt was the cause of the issue. Installing via npm npm install grunt -g corrected the problem. Given an existing global grunt install from apt, you might need to add --force to overwrite.
I'm trying to do a quick experiment or two with Jenkins. For this I intended to use the jenkins image and add nodejs and npm to it. Here's what I'm trying to do:
FROM jenkins
USER root
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
&& apt-get update \
&& apt-get install -y \
nodejs
RUN npm install -g npm
RUN npm --version
USER jenkins
The npm --version call will fail though, with this error:
Step 5/6 : RUN npm --version
---> Running in 48a250a4fdb8
module.js:471
throw err;
^
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
The command '/bin/sh -c npm --version' returned a non-zero code: 1
What is the proper way (if any) to fix this?
Try the following, it uses docker multi-stage build to copy dependencies from one image to another. This will allow you to avoid all the special things that need to be done to install node in docker. There is an official docker image that is built by the docker team, so you use that as follows:
FROM node
FROM jenkins
USER root
COPY --from=0 /usr/local /usr/local
RUN npm --version
USER jenkins
npm --version will output 5.3.0
Jenkins image by docker uses minimal installation for running Jenkins
FROM node:15.4 as nodejs
ENV JENKINS_HOME /var/jenkins_home
USER root
RUN rm -rf /var/lib/apt/lists/*
RUN rm -rf /etc/apt/sources.list.d/*
RUN apt-get update
#INSTALL NODE
COPY --from=nodejs /usr/local /usr/local
RUN node -v
RUN npm -v
module.js:340
throw err;
^
Error: Cannot find module 'vinyl'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/morpheyesh/debugall/web-starter-kit/node_modules/gulp/node_modules/gulp-util/lib/File.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I have major issues with node.js. I try to run any nodejs application or gulp, i get this error, I try to install every module , I keep getting the same error and it requires a new module. Is there anyway where I can install all the modules?
Plus, I have install nodejs through npm? how to install system wide? Gulp is been installed system wide(global). What is causing this error?
nodejs -v gives v0.10.30
`npm -v gives 1.4.21
gulp 3.8.7
I am working with the google web starter kit. I installed nodejs using apt-get, then install sass, then installed gulp, then npm. Is there a way where I can remove all these and install all of it system wide?
Try updating your global gulp installation:
sudo npm install --global gulp#latest
It sounds like everything is (was?) FUBAR for a while there. If you have not yet solved these problems, here's what I would recommend.
First, the official (Debian/Ubuntu) packages are a bit behind latest node. I would recommend uninstalling the packages nodejs and nodejs-legacy and following the instructions here to get the latest versions (packaged and published by nodesource): https://github.com/nodesource/distributions#usage-instructions
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
Now you will have a recent node (0.10.35) but an out-of-date npm. Upgrade your npm:
npm install -g npm#latest
Things should now work for you; you should be able to run npm install in your project directory and all dependencies will be installed correctly.
One thing to be wary of is that you should never run npm update or npm update -g. This does not update the current (or all global) packages, as one might think.
Try this for install all plugins required by gulp :
npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev
Source : http://travismaynard.com/writing/getting-started-with-gulp
For me uninstalling gulp and then reinstalling it worked fine. This is with node v5.0.0
sudo npm uninstall -g gulp
npm install -g gulp
I am trying to use express in an ubuntu 13.10 distribution. I am using node version 0.10.29 and npm 1.4.14 When I use express this is my output:
module.js:340
throw err;
^
Error: Cannot find module 'mkdirp'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/usr/bin/express:10:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Additionally, I have to use sudo npm as npm doesn't work (i'm not sure if that's part of the issue - but I suspect path issues, not really sure). I have googled but haven't been able to fix the issues.
Edit: I think I messed up my path. I am unable to reinstall npm. Here is output from $PATH
bash: /home/qtrain/npm/bin:/usr/bin/yo:/home/qtrain/.node/bin:/home/qtrain/Enthought/Canopy_64bit/User/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/qtrain/.rvm/bin:/home/qtrain/.rvm/bin:/home/qtrain/.rvm/bin:
The mkdirp error seems to originate from using the chris-lea repo for node.js as Michael answered.
To fix: eliminate the PPA and node itself, then reinstall as below.
1.) sudo apt-get install ppa-purge - if you don't already have it
2.) sudo ppa-purge ppa:chris-lea/node.js
3.) sudo apt-get remove nodejs
4.) sudo apt-get remove npm
5.) sudo apt-get autoremove
6.) sudo apt-get install nodejs
7.) sudo apt-get install npm
8.) sudo apt-get install node-express
I ran into a similar problem while using npm and express. My solution was to uninstall node from my entire system using sudo apt-get remove nodejs
Then I reinstalled node from source following directions here http://chimera.labs.oreilly.com/books/1234000001808/ch01.html#chap5_id35941617
Then I had to install npm separately using sudo apt-get install npm but it still didn't work.
It was then that I realized that ppa repos I had installed from chris lea were not configured for 13.10
https://launchpad.net/~chris-lea/+archive/ubuntu/node.js-legacy
Removed them and reinstalled npm using sudo apt-get install npm and installed express with sudo apt-get install node-express
I was then able to use npm and express
Hope this helps..
Tried to install node.js with coffeescript like this:
sudo sudo apt-get install nodejs npm
sudo npm install -g coffee-script
But:
coffee -v
Returns me:
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
at Function.Object.defineProperty.get (module.js:388:11)
at Object.<anonymous> (/home/lapsa/bin/coffee#1.3.0:4:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:903:3
I'm completely lost at the moment. Any help?
Tried this approach w/o success.
$ npm -v
1.2.15
$ node -v
v0.11.0-pre
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.2 LTS
Release: 12.04
Codename: precise
This solution worked for me (tested on both Ubuntu 12.04 and 13.04):
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo npm install -g coffee-script
Source:
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
Note that it does not use the default Ubuntu package npm. Instead npm is packaged with in Chris Lea's nodejs package.
If you already have npm installed, you might want to remove it first before applying the workaround above. Note that there is also a naming conflict with a package named node but which has nothing to do with nodejs. If you installed that package by accident, you might also want to remove it.
I'm wondering if your problem is related to trying to install npm using
sudo apt-get install nodejs npm
If you take a look at the instructions for installing nodejs via package manager it states that
As of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.
I wonder if a rogue installed version of an npm package is causing you a problem. I ran into this the other day but for me, npm just wouldn't install.