node.js - npm链接包名必须有name字段才能链接

标签 node.js docker npm

嗨,我正在尝试创建一个 docker 镜像。 下面是我的 docker 文件的一部分,它导致了问题。我认为问题是由于 nodejs 包造成的。

当前的软链接(soft link)是: ls -la“/usr/bin/npm” lrwxrwxrwx 1 root root 3月2日25日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

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

最佳答案

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

npm-link 中所述:

Note that package-name is taken from package.json, not from directory name

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

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

关于node.js - npm链接包名必须有name字段才能链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49065806/

相关文章:

node.js - 如何使用 Firestore 从 DialogFlow 实现上的 snap 中获取 map 数组

javascript - 函数导出未按预期工作

node.js - Docker 远程 API 和绑定(bind)

node.js - heroku -- npm postinstall 脚本根据 enviro 运行 grunt 任务

node.js - 如何在 Azure DevOps 构建结果中添加新选项卡以显示 HTML 内容?

node.js - Firebase 函数仅返回 null

docker - 带有URL路径的Docker满

docker - 使docker-machine在不使用tlsverify的情况下创建主机

node.js - 将 Node.js 包发布到 NPM 以外的地方

docker - npm install 在 docker 的 jenkins 管道中失败