npm链接包名称必须具有要链接的名称字段

时间:2018-03-02 09:03:24

标签: node.js docker npm

您好我正在尝试创建一个泊坞窗图片。 下面是我的docker文件的一部分导致问题。我认为问题是由nodejs包引起的。

目前的软链接是:  ls -la" / usr / bin / npm" lrwxrwxrwx 1 root root 25 Mar 2 01:50 / usr / bin / npm - > / usr / lib中/ node_modules / NPM

非root用户安装

Docker文件

 #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   

以下是docker构建输出:

     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

任何帮助都将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

问题是生成的package.json没有name属性集"name": "",

npm-link中所述:

  

请注意,package-name取自package.json,而不是目录名

namepackage.json为空的原因是您在容器的根npm init中运行/。 您必须创建一个目录并在那里运行npm init

...
WORKDIR /app
RUN npm init -y
...