npm install not creating node_modules inside dockerfile - node.js

I am using a dockerfile to define a custom Wordpress distribution that uses React in frontend (via special theme).
To do that I am modifying the official Wordpress dockerfile and adding the theme, wget and npm as dependencies.
The problem is at the end of the dockerfile in the CUSTOM PART. npm install does not create the node_modules directory, but finishes successfully (just WARN messages). Then npm start fails gives the ERROR, because the rimraf and webpack npm packages are not installed.
Why is /var/www/html/wp-content/themes/lexi-master/node_modules not being created?
The error:
sh: 1: rimraf: not found
npm ERR! Linux 4.4.20-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "clean"
npm ERR! node v7.4.0
npm ERR! npm v4.1.1
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! Lexi-WP-Theme#0.0.1 clean: `rimraf dist`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the Lexi-WP-Theme#0.0.1 clean script 'rimraf dist'.
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 Lexi-WP-Theme package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! rimraf dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs Lexi-WP-Theme
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls Lexi-WP-Theme
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/html/wp-content/themes/lexi-master/npm-debug.log
npm ERR! Linux 4.4.20-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.4.0
npm ERR! npm v4.1.1
npm ERR! code ELIFECYCLE
npm ERR! Lexi-WP-Theme#0.0.1 build: `npm run clean && webpack`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Lexi-WP-Theme#0.0.1 build script 'npm run clean && webpack'.
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 Lexi-WP-Theme package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run clean && webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs Lexi-WP-Theme
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls Lexi-WP-Theme
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/html/wp-content/themes/lexi-master/npm-debug.log
npm ERR! Linux 4.4.20-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "--prefix" "/var/www/html/wp-content/themes/lexi-master" "start"
npm ERR! node v7.4.0
npm ERR! npm v4.1.1
npm ERR! code ELIFECYCLE
npm ERR! Lexi-WP-Theme#0.0.1 start: `npm run build && node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Lexi-WP-Theme#0.0.1 start script 'npm run build && node server.js'.
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 Lexi-WP-Theme package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run build && node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs Lexi-WP-Theme
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls Lexi-WP-Theme
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/html/npm-debug.log
The command '/bin/sh -c npm --prefix /var/www/html/wp-content/themes/lexi-master start' returned a non-zero code: 1
Possible cause in dockerfile (line with npm install):
RUN cd /var/www/html/wp-content/themes/lexi-master; npm install
...whole dockerfile (only CUSTOM PART was added):
FROM php:7.1-apache
# install the PHP extensions we need
RUN set -ex; \
\
apt-get update; \
apt-get install -y \
libjpeg-dev \
libpng12-dev \
; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-install gd mysqli opcache
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN a2enmod rewrite expires
VOLUME /var/www/html
ENV WORDPRESS_VERSION 4.7.1
ENV WORDPRESS_SHA1 8e56ba56c10a3f245c616b13e46bd996f63793d6
RUN set -ex; \
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
tar -xzf wordpress.tar.gz -C /usr/src/; \
rm wordpress.tar.gz; \
chown -R www-data:www-data /usr/src/wordpress
COPY docker-entrypoint.sh /usr/local/bin/
# CUSTOM PART START
COPY lexi-master /var/www/html/wp-content/themes/lexi-master
# Install wget
RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
# Install dependencies
RUN apt-get update && apt-get install -y \
software-properties-common
# RUN add-apt-repository universe
RUN apt-get update && apt-get install -y \
apache2 \
curl \
git \
libapache2-mod-php5 \
php5 \
php5-mcrypt \
php5-mysql \
python3.4 \
python3-pip
# Install Node.js
RUN \
cd /tmp && \
wget http://nodejs.org/dist/node-latest.tar.gz && \
tar xvzf node-latest.tar.gz && \
rm -f node-latest.tar.gz && \
cd node-v* && \
./configure && \
CXX="g++ -Wno-unused-local-typedefs" make && \
CXX="g++ -Wno-unused-local-typedefs" make install && \
cd /tmp && \
rm -rf /tmp/node-v* && \
npm install -g npm && \
printf '\n# Node.js\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc
RUN cd /var/www/html/wp-content/themes/lexi-master; npm install
RUN echo "export const WP_URL = '<http://www.example.com/wp-json/wp/v2';" > /var/www/html/wp-content/themes/lexi-master/src/wp-url.js
# Test the installation
RUN ls /var/www/html/wp-content/themes/lexi-master/
RUN ls /var/www/html/wp-content/themes/lexi-master/node_modules
# Start the server
RUN cd /var/www/html/wp-content/themes/lexi-master; npm start
# CUSTOM PART END
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]
/var/www/html/wp-content/themes/lexi-master/package.json:
{
"name": "Lexi-WP-Theme",
"version": "0.0.1",
"description": "",
"license": "MIT",
"dependencies": {
"history": "^1.9.0",
"isomorphic-fetch": "^2.1.1",
"react": "^0.14.0-rc1",
"react-dom": "^0.14.3",
"react-redux": "^3.0.1",
"react-router": "1.0.0-rc1",
"redux": "^3.0.2",
"redux-thunk": "^1.0.0"
},
"devDependencies": {
"babel-core": "^5.6.18",
"babel-loader": "^5.1.4",
"css-loader": "^0.18.0",
"debug": "^2.2.0",
"extract-text-webpack-plugin": "^0.8.2",
"file-loader": "^0.8.4",
"html-webpack-plugin": "^1.6.1",
"react-hot-loader": "^1.3.0",
"rimraf": "^2.5.0",
"style-loader": "^0.12.3",
"webpack": "^1.9.11",
"webpack-dev-server": "^1.9.0"
},
"scripts": {
"clean": "rimraf dist",
"build": "npm run clean && webpack",
"start": "npm run build && node server.js"
}
}

Related

NPM install fails with NVM and Docker

I am using NVM to install Node.js 16.15.0 inside a Docker container.
I get an error when running npm ci:
npm ERR! command failed
npm ERR! command sh -c node lib/install.js
npm ERR! /atomix/node_modules/npm-conf/lib/conf.js:169
npm ERR! throw err;
npm ERR! ^
npm ERR!
npm ERR! Error: EACCES: permission denied, stat '/root/.nvm/versions/node/v16.15.0'
npm ERR! at Object.statSync (fs.js:898:3)
npm ERR! at Conf.loadUser (/atomix/node_modules/npm-conf/lib/conf.js:162:21)
npm ERR! at module.exports (/atomix/node_modules/npm-conf/index.js:32:7)
npm ERR! at Object.<anonymous> (/atomix/node_modules/get-proxy/index.js:2:36)
npm ERR! at Module._compile (internal/modules/cjs/loader.js:936:30)
npm ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
npm ERR! at Module.load (internal/modules/cjs/loader.js:790:32)
npm ERR! at Function.Module._load (internal/modules/cjs/loader.js:703:12)
npm ERR! at Module.require (internal/modules/cjs/loader.js:830:19)
npm ERR! at require (internal/modules/cjs/helpers.js:68:18) {
npm ERR! errno: -13,
npm ERR! syscall: 'stat',
npm ERR! code: 'EACCES',
npm ERR! path: '/root/.nvm/versions/node/v16.15.0'
npm ERR! }
My Dockerfile:
FROM trzeci/emscripten
EXPOSE 8080/tcp
RUN apt update \
&& apt install libglew-dev -y \
&& wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash \
&& apt install htop \
&& apt install procps -y
ENV NVM_DIR /root/.nvm
ENV NODE_VERSION 16.15.0
RUN chmod +x $HOME/.nvm/nvm.sh
RUN . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
WORKDIR /atomix
RUN npm i flow-typed -g
# NPM 7+ automatically installs peer deps so disable this as it fails our install
RUN npm config set legacy-peer-deps true
These installation instructions for NVM are copied from NVM itself.
When I roll it back from 16.15.0 to 10.16.0 (which I know works) it works successfully. Why does the newer version of Node.js fail?
I would suggest using one of the official Node.JS Docker images for whatever part you need Node for. You can use a build arg to specify the version.
Use a multi-stage build to create whatever assets you need for the Node stage.
ARG NODE_VERSION=16.5
# Build stage
FROM emscripten/emsdk AS emcc
WORKDIR /build
COPY your-src-files/ ./
RUN emcc ...
# Run
FROM node:${NODE_VERSION}
WORKDIR /atomix
RUN npm config set legacy-peer-deps true
RUN npm i flow-typed -g
COPY --from=emcc /build/your-compiled-files ./
RUN ...
To change the Node version, you simply build the image with a NODE_VERSION build arg...
docker build --build-arg NODE_VERSION=17 .

Unable to install NPM inside Docker

I have a project that builds locally, and I try to create a Docker image.
In my project, I install NPM packages, and my package file is located at:
\src\Core.Blazor\package.json
But, when I try to build my Docker image, it failed with the following error:
npm ERR! code ENOLOCAL
npm ERR! Could not install "src/Core.Blazor/package.json" as it is not a directory and is not a file with a name ending in .tgz, .tar.gz or .tar
I join the Dockerfile too:
### >>> GLOBALS
ARG ENVIRONMENT="Production"
ARG PROJECT="PyProd.IdentityServer.Host"
### <<<
# debian buster - AMD64
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
### >>> IMPORTS
ARG ENVIRONMENT
ARG PROJECT
### <<<
ARG NUGET_CACHE=https://api.nuget.org/v3/index.json
ARG NUGET_FEED=https://api.nuget.org/v3/index.json
# Copy sources
COPY src/ /app/src
ADD common.props /app
WORKDIR /app
# Installs NodeJS to build typescripts
RUN apt-get update
RUN apt-get install curl
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
RUN npm install /app/src/Core.Blazor/package.json
After trying to fix with the following, I also get an error:
RUN npm install /app/src/SmartPixel.Core.Blazor/
Here is the error I got:
> aspnet-parcel-exp#0.1.0 build /app/src/SmartPixel.Core.Blazor
> parcel build wwwroot/assets/blazorcore.js --out-dir wwwroot/dist/
sh: 1: parcel: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! aspnet-parcel-exp#0.1.0 build: `parcel build wwwroot/assets/blazorcore.js --out-dir wwwroot/dist/`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the aspnet-parcel-exp#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
I also join the package.json file:
{
"name": "aspnet-parcel-exp",
"private": true,
"version": "0.1.0",
"devDependencies": {
"parcel": "1.12.3"
},
"includePaths": [
"./wwwroot/assets/js",
"./wwwroot/assets/css"
],
"scripts": {
"build": "parcel build wwwroot/assets/blazorcore.js --out-dir wwwroot/dist/",
"watch": "parcel watch wwwroot/assets/blazorcore.js --out-dir wwwroot/dist/"
}
}
I don't know NodeJS, but as your error says:
npm ERR! Could not install "src/Core.Blazor/package.json" as it is not a directory and is not a file with a name ending in .tgz, .tar.gz or .tar
I believe you should change your Dockerfile to this:
RUN npm install /app/src/Core.Blazor/
Or even this:
RUN npm install /app/src/Core.Blazor
As the second one doesn't have trailing slash.

on giving npm start in command prompt in react js

I am getting the below error every time in my command prompt basically I am unable to open my server because of the start in package.json is throwing the error, i am not able to find what issue is, please advice what is the correct way
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\user>d:
D:>cd reactApp
D:\reactApp>npm install -g npm#latest
C:\Users\user\AppData\Roaming\npm\npm -> C:\Users\user\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
C:\Users\user\AppData\Roaming\npm\npx -> C:\Users\user\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
+ npm#5.8.0
added 523 packages in 116.024s
D:\reactApp>rm -rf node_modules
'rm' is not recognized as an internal or external command,
operable program or batch file.
D:\reactApp>npm -rf node_modules
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, ci, completion,
config, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, get, help, help-search, i, init, install,
install-test, it, link, list, ln, login, logout, ls,
outdated, owner, pack, ping, prefix, profile, prune,
publish, rb, rebuild, repo, restart, root, run, run-script,
s, se, search, set, shrinkwrap, star, stars, start, stop, t,
team, test, token, tst, un, uninstall, unpublish, unstar,
up, update, v, version, view, whoami
npm -h quick help on
npm -l display full usage info
npm help search for help on
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\user\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#5.8.0 C:\Users\user\AppData\Roaming\npm\node_modules\npm
D:\reactApp>npm install
npm WARN babel-loader#7.1.4 requires a peer of babel-core#6 but none is installed. You must install peer dependencies yourself.
npm WARN reactapp#1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
removed 10 packages in 21.906s
D:\reactApp>npm start
> reactapp#1.0.0 start D:\reactApp
> npm run build
> reactapp#1.0.0 build D:\reactApp
> webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 build: `webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-03-27T03_57_54_881Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 start: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-03-27T03_57_54_983Z-debug.log
D:\reactApp>npm install -g react-scripts
C:\Users\user\AppData\Roaming\npm\react-scripts -> C:\Users\user\AppData\Roaming\npm\node_modules\react-scripts\bin\react-scripts.js
> uglifyjs-webpack-plugin#0.4.6 postinstall C:\Users\user\AppData\Roaming\npm\node_modules\react-scripts\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js
npm WARN ajv-keywords#3.1.0 requires a peer of ajv#^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\react-scripts\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ react-scripts#1.1.1
added 1324 packages from 785 contributors in 453.077s
D:\reactApp>npm start
> reactapp#1.0.0 start D:\reactApp
> npm run build
> reactapp#1.0.0 build D:\reactApp
> webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 build: `webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-03-27T04_06_58_572Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 start: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-03-27T04_06_58_697Z-debug.log
D:\reactApp>npm start
my package.json file is
{
"name": "reactapp",
"version": "1.0.0",
"description": "some basics reactjs",
"main": "index.js",
"scripts": {
"start": "npm run build",
"build": "webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
"build:prod": "webpack -p && cp src/index.html dist/index.html"
},
"keywords": [
"reactjs"
],
"author": "Harsh mewari",
"license": "ISC",
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"devDependencies": {
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"webpack": "^4.2.0",
"webpack-dev-server": "^3.1.1"
}
}
my webpack.config.js file is
var path=require("path");
var DIST_DIR = path.resolve(dirname,"dist");
var SRC_DIR= path.resolve(_dirname,"src");
var config={
entry: SRC_DIR + "/app/index.js",
output:{
path: DIST_DIR + "/app",
filename:"bundle.js",
publicPath:"/app"
},
modules:{
loaders:[
{
test:/\.js?/,
include: SRC_DIR,
loader:"babel-loader",
query:{
presets:["react","es2015","stage-2"]
}
}
]
};
module.exports= config;
}

npm link package name must have a name field to be linked

Hi I am trying to create a docker image.
Below is a part of my docker file which is causing problem.I think the problem is due to nodejs package.
The current softlink is:
ls -la "/usr/bin/npm"
lrwxrwxrwx 1 root root 25 Mar 2 01:50 /usr/bin/npm -> /usr/lib/node_modules/npm
Installation is does by a nonroot user
Docker File
#Install node js and npm
RUN curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN apt-get -y install nodejs
RUN npm install -g bower gulp
RUN npm install -g node-gyp#latest --save
RUN npm init -y
RUN npm install -g n
RUN npm install zmq --save
RUN ldconfig
RUN npm config set prefix ~/npm
#RUN npm install -g stf t
#RUN npm install
#RUN rm -rf /usr/bin/npm
#RUN ln -s /usr/lib/node_modules/npm/ /usr/bin/npm
RUN npm link
Below is the docker build output:
Step 35/42 : RUN npm init -y
---> Running in abf773c34e35
Wrote to /package.json:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Step 38/42 : RUN ldconfig
---> Running in 1562e282d324
Removing intermediate container 1562e282d324
---> bdf746069a90
Step 39/42 : RUN npm config set prefix ~/npm
---> Running in 400512f792d0
Removing intermediate container 400512f792d0
---> 0f3eeb03910c
Step 40/42 : RUN npm link
---> Running in 40ae29419291
npm ERR! Linux 4.4.0-98-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "link"
npm ERR! node v6.13.0
npm ERR! npm v3.10.10
npm ERR! Package must have a name field to be linked
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /npm-debug.log
The command '/bin/sh -c npm link' returned a non-zero code: 1
Any help would be appreciated.Thanks
The problem is that the generated package.json does not have the name property set "name": "",.
As documented in npm-link:
Note that package-name is taken from package.json, not from directory name
The reason why name is empty in package.json is that you are running npm init in the root / of the container.
You have to create a directory and run npm init in there.
...
WORKDIR /app
RUN npm init -y
...

npm install error ENOTDIR

I am very new to Node.js and trying to install Flatiron using npm but it gives me an error.
sudo npm install flatiron -g
And I get -
npm http GET https://registry.npmjs.org/flatiron
npm http 304 https://registry.npmjs.org/flatiron
npm ERR! Error: ENOTDIR, mkdir '/home/siddharthsaha/tmp/npm-28554/1353323290836-0.20847953506745398'
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 3.2.0-24-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "flatiron" "-g"
npm ERR! cwd /home/siddharthsaha/denarit
npm ERR! node -v v0.8.14
npm ERR! npm -v 1.1.65
npm ERR! path /home/siddharthsaha/tmp/npm-28554/1353323290836-0.20847953506745398
npm ERR! code ENOTDIR
npm ERR! errno 27
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/siddharthsaha/denarit/npm-debug.log
npm ERR! not ok code 0
What is wrong here? I have no clue.
Just solved the issue. Its because there's a file called tmp in the home directory.
rm -rf ~/tmp
sudo npm cache clear
sudo npm install -g node
Also... if you are trying to install npm then the same error and solution applies - delete ~/tmp
Try
sudo mkdir -p /home/siddharthsaha/tmp
sudo npm cache clear
before starting the install script, since npm http 304 https://registry.npmjs.org/flatiron line states that this module is coming from cache. And also ENOTDIR states that there is no directory. Therefore, emptying the cache would solve your problem.
Below are the steps to install a given release from source without root
NOTE - this installs nodejs which gives you both node as well as npm,
they come together per release.
to start fresh remove prior node.js and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
to install nodejs and npm as yourself NOT root do these commands (OSX/linux) :
export NODE_PARENT=${HOME}/bin_0_10_32
mkdir ${NODE_PARENT}
download source from : http://nodejs.org/download/
cd node-v0.xxxx
./configure --prefix=${NODE_PARENT}/nodejs
make -j8
make install # IMPORTANT this is NOT using sudo
# not wanted since installing into $USER owned $NODE_PARENT
which puts it into dir defined by above --prefix
export PATH=${NODE_PARENT}/nodejs/bin:$PATH
define environment variable NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into current dir :
export NODE_PATH=${NODE_PARENT}/nodejs/lib/node_modules
when you use syntax : npm install -g some_cool_module
the -g for global installs it into dir $NODE_PATH and not your $PWD
nodejs install gives you npm as well :
ls -la ${NODE_PARENT}/nodejs/bin
Subsequent modules you install using global flag -g will automagically put
their ~binaries~ into above bin dir ... like browserify
Now put above three export xxx=yyy
commands into your ~/.bashrc or some such so your environment is setup
I direct delete the file of npm-debug.log.
then it's ok for me.

Resources