在Docker中运行时,`npm install`导致`cb()never called!`

ymzxtsji  于 4个月前  发布在  Docker
关注(0)|答案(2)|浏览(73)

我有一个相当小的package.json文件的项目:

{
    "name": "chilldev-web",
    "version": "2.1.0-SNAPSHOT",
    "description": "Client-side build tool for a project.",
    "license": "UNLICENSED",
    "private": true,
    "dependencies": {
        "internal-edge-render": "file:/root/.m2/repository/pl/chilldev/internal/internal-edge-render/0.1.2/internal-edge-render-0.1.2.tar.gz",
        "react": "16.6.1",
        "react-dom": "16.6.1",
        "react-helmet": "5.2.0",
        "director": "1.2.8"
    },
    "devDependencies": {
        "typescript": "2.9.2",
        "browserify": "16.2.3",
        "gulp": "3.9.1",
        "tslint": "5.11.0",
        "tslint-react": "3.6.0",
        "cssnano": "4.1.7",
        "autoprefixer": "9.3.1",
        "envify": "4.1.0",
        "uglifyify": "5.0.1",
        "sassdoc": "2.5.1",
        "typedoc": "0.13.0",
        "gulp-typedoc": "2.2.0",
        "gulp-postcss": "8.0.0",
        "gulp-tslint": "8.1.3",
        "gulp-jscpd": "0.0.8",
        "gulp-sass": "4.0.2",
        "gulp-typescript": "4.0.2",
        "gulp-install": "1.1.0",
        "gulp-zip": "4.2.0",
        "gulp-concat": "2.6.1",
        "gulp-header": "2.0.5",
        "gulp-uglify": "3.0.1",
        "vinyl-source-buffer": "1.1.1",
        "@types/whatwg-streams": "0.0.7",
        "@types/google.analytics": "0.0.39",
        "@types/react": "16.4.18",
        "@types/react-dom": "16.0.9",
        "@types/react-helmet": "5.0.7",
        "@types/headroom": "0.7.31",
        "@types/aws-lambda": "8.10.15",
        "bourbon": "5.1.0",
        "susy": "3.0.5"
    }
}

字符串
当使用Node/NPM的本地安装时,它可以正常工作(Node v11.0.0,NPM v6.4.1)来执行全新安装(rm -rf node_modules && npm install)。
但是当运行一个Dockerized任务时(这会影响CI管道),我得到了一个cb() never called!错误:

root@4b8396e40e22:/usr/src/app# npm install --loglevel=verbose                                                                                                                                                                                                                 
npm info it worked if it ends with ok                                                                                                                                                                                                                                          
npm verb cli [ '/usr/local/bin/node',                                                                                                                                                                                                                                          
npm verb cli   '/usr/local/bin/npm',                                                                                                                                                                                                                                           
npm verb cli   'install',                                                                                                                                                                                                                                                      
npm verb cli   '--loglevel=verbose' ]                                                                                                                                                                                                                                          
npm info using [email protected]                                                                                                                                                                                                                                                       
npm info using [email protected]                                                                                                                                                                                                                                                    
npm verb npm-session c4ce6e4ee1ed4de0                                                                                                                                                                                                                                          
npm info lifecycle [email protected]~preinstall: [email protected]
npm timing stage:loadCurrentTree Completed in 14ms                                                                                                                                                                                                                             
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms                                                                                                                                                                                                               
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 899ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 1603ms
npm timing stage:loadIdealTree Completed in 3006ms
npm timing stage:generateActionsToTake Completed in 390ms
npm verb correctMkdir /root/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /root/.npm/_locks/staging-af89dff005e44f9e.lock for /usr/src/app/node_modules/.staging
npm timing audit compress Completed in 108ms
npm info audit Submitting payload of 62503bytes
npm timing audit submit Completed in 1539ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 1539ms
npm timing audit body Completed in 1ms
npm timing action:extract Completed in 6742ms
npm timing action:finalize Completed in 940ms
npm timing npm Completed in 14338ms
npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-11-07T19_09_16_380Z-debug.log


只需再次运行该任务即可使其成功:

root@4b8396e40e22:/usr/src/app# npm install --loglevel=verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   '--loglevel=verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb npm-session efbf901b4a03cead
npm info lifecycle [email protected]~preinstall: [email protected]
npm timing stage:loadCurrentTree Completed in 2177ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 21ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1153ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 1463ms
npm timing stage:loadIdealTree Completed in 3225ms
npm timing stage:generateActionsToTake Completed in 103ms
npm verb correctMkdir /root/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /root/.npm/_locks/staging-af89dff005e44f9e.lock for /usr/src/app/node_modules/.staging
npm verb unlock done using /root/.npm/_locks/staging-af89dff005e44f9e.lock for /usr/src/app/node_modules/.staging
npm timing stage:executeActions Completed in 16ms
npm timing stage:rollbackFailedOptional Completed in 0ms
npm info linkStuff [email protected]
npm info lifecycle [email protected]~install: [email protected]
npm info lifecycle [email protected]~postinstall: [email protected]
npm timing audit compress Completed in 25ms
npm info audit Submitting payload of 62503bytes
npm info lifecycle [email protected]~prepublish: [email protected]
npm info lifecycle [email protected]~prepare: [email protected]
npm timing stage:runTopLevelLifecycles Completed in 6162ms
npm verb saving []
npm verb shrinkwrap skipping write for package.json because there were no changes.
npm info lifecycle undefined~preshrinkwrap: undefined
npm info lifecycle undefined~shrinkwrap: undefined
npm verb shrinkwrap skipping write for package-lock.json because there were no changes.
npm info lifecycle undefined~postshrinkwrap: undefined
npm timing audit submit Completed in 2165ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 2019ms
npm timing audit body Completed in 3ms
audited 4746 packages in 8.13s
found 6 vulnerabilities (2 low, 4 high)
run `npm audit fix` to fix them, or `npm audit` for details
npm verb exit [ 0, true ]
npm timing npm Completed in 8439ms
npm info ok


上面的命令是在Docker镜像node:11.0.0中执行的。但是当我尝试在不同的镜像中安装Node时(例如,如果我使用maven:3.5.2-jdk-8来运行绑定了npm install的Maven项目),会出现相同的结果。

  • 编辑-
    还有一个细节-为了解决Docker执行后文件所有权的问题,我使用bindfs
DIR=`mktemp -d`
sudo bindfs --create-for-user=`id -nu` --create-for-group=`id -ng` $PWD $DIR
docker run --rm -it -v $DIR:/usr/src/app -w /usr/src/app node:11.0.0 npm install


当我只使用-v $PWD:/usr/src/app而不是临时挂载点运行Docker时,一切都很好!

1dkrff03

1dkrff031#

您有一个正在尝试安装的本地依赖项。
1x个月
Docker不知道它的路径。要么从npm安装依赖项,要么将目录挂载到docker中。假设后者是没有选择的话...
不幸的是,日志在这种情况下并没有真正的帮助。

vh0rcniy

vh0rcniy2#

将docker网络设置为“host”为我解决了这个问题和其他问题。

docker build . --network host

字符串

相关问题