SlickTester
SlickTester

Reputation: 137

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

Upvotes: 1

Views: 3954

Answers (1)

yamenk
yamenk

Reputation: 51836

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
... 

Upvotes: 2

Related Questions