gpt4 book ai didi

node.js - Docker 无法从 package.json 文件安装依赖项

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:35 25 4
gpt4 key购买 nike

我是 Docker 新手,正在尝试将我的团队构建的 Node 应用程序容器化。不幸的是,它似乎没有构建 happy.js,这是我的 package.json 文件中明确说明的依赖项。这是我的 DockerFile 的副本:

FROM node:8-alpine

WORKDIR /usr/src/app

ENV UV_THREADPOOL_SIZE 64

COPY cdp-contracts/ ./rpc
COPY cdp-platform/ ./backend

RUN rm -rf backend/node_modules
RUN rm -rf rpc/node_modules

RUN apk add --no-cache --virtual .gyp \
autoconf \
automake \
g++ \
libpng-dev \
libtool \
make \
nasm \
python \
git \
&& npm i -g wait-on concurrently truffle npm@latest \
# && concurrently 'cd rpc; npm init -y ; npm install --save-exact openzeppelin-solidity; npm init -y ; npm i npm@latest -g ' \
# && concurrently 'cd backend; npm init -y ; npm i npm@latest -g ; npm i hapi -g; npm rebuild bcrypt --build-from-source' \
&& concurrently 'cd rpc; npm init -y ; npm install --save-exact openzeppelin-solidity; npm init -y ; npm i npm@latest -g ' \
&& concurrently 'cd backend; npm init -y ; npm i npm@latest -g ; npm i hapi -g; npm rebuild bcrypt --build-from-source' \
&& apk del .gyp

WORKDIR /usr/src/app/rpc

RUN truffle compile --all

WORKDIR /usr/src/app/backend

RUN mkdir -p build/
RUN ln -sf ../../rpc/build/contracts build/contracts

WORKDIR /usr/src/app/backend

EXPOSE 3001

CMD [ "npm", "run", "middleware" ]

问题出在后端文件夹中。以下是复制到此文件夹的 package.json 文件的副本:

{
"name": "cdp-platform",
"version": "0.1.0",
"description": "the main platform for CDP",
"main": "server.js",
"private": true,
"scripts": {
"test": "echo ok",
"space{0}": "--- Services ------------------------------------------------",
"middleware": "node ./middleware/server.js",
"middleware:debug": "node --nolazy --inspect-brk=9229 ./middleware/server.js"
},
"repository": {},
"keywords": [],
"author": "",
"license": "",
"dependencies": {
"agentkeepalive": "3.1.0",
"async": "2.5.0",
"axios": "0.18.0",
"bcrypt": "2.0.1",
"bignum": "0.12.5",
"bluebird": "3.5.0",
"boom": "6.0.0",
"csv": "3.1.0",
"csv-parse": "2.5.0",
"documentdb": "1.14.4",
"good": "7.1.0",
"good-console": "6.4.0",
"good-squeeze": "5.0.2",
"greenlock": "2.1.12",
"greenlock-cli": "2.2.6",
"hapi": "16.1.0",
"hapi-auth-jwt2": "7.2.4",
"hapi-authorization": "3.0.3",
"hapi-swagger": "7.9.1",
"http-duplex": "0.0.2",
"inert": "4.2.1",
"is-stream": "1.1.0",
"isemail": "3.0.0",
"joi": "13.0.0",
"jsonwebtoken": "8.1.0",
"lodash": "4.17.10",
"moment": "2.22.1",
"mongodb": "3.0.10",
"pm2": "2.6.1",
"request": "2.80.0",
"scramjet": "4.15.3",
"semver": "5.3.0",
"through": "^2.3.8",
"through2": "^2.0.3",
"toobusy-js": "^0.5.1",
"uuid": "^3.0.1",
"vision": "^4.1.1",
"winston": "^2.3.1",
"xss": "^0.3.3"
},
"devDependencies": {
"babel-eslint": "^8.0.1",
"chai": "^4.1.2",
"eslint": "^4.9.0",
"istanbul": "^0.4.5",
"mocha": "^5.1.1",
"mockery": "^2.0.0",
"nock": "^9.0.9",
"sinon": "^5.0.7"
}
}

不幸的是,我不断收到此错误:

backend_1   | > cdp-platform@0.1.0 middleware /usr/src/app/backend
backend_1 | > node ./middleware/server.js
backend_1 |
backend_1 | module.js:550
backend_1 | throw err;
backend_1 | ^
backend_1 |
backend_1 | Error: Cannot find module 'hapi'
backend_1 | at Function.Module._resolveFilename (module.js:548:15)
backend_1 | at Function.Module._load (module.js:475:25)
backend_1 | at Module.require (module.js:597:17)
backend_1 | at require (internal/module.js:11:18)
backend_1 | at Object.<anonymous> (/usr/src/app/backend/middleware/server.js:2:14)
backend_1 | at Module._compile (module.js:653:30)
backend_1 | at Object.Module._extensions..js (module.js:664:10)
backend_1 | at Module.load (module.js:566:32)
backend_1 | at tryModuleLoad (module.js:506:12)
backend_1 | at Function.Module._load (module.js:498:3)
backend_1 | npm ERR! code ELIFECYCLE
backend_1 | npm ERR! errno 1
backend_1 | npm ERR! cdp-platform@0.1.0 middleware: `node ./middleware/server.js`
backend_1 | npm ERR! Exit status 1
backend_1 | npm ERR!
backend_1 | npm ERR! Failed at the cdp-platform@0.1.0 middleware script.
backend_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
backend_1 |
backend_1 | npm ERR! A complete log of this run can be found in:
backend_1 | npm ERR! /root/.npm/_logs/2018-12-04T07_48_39_145Z-debug.log

我将非常感谢对此的任何指示

最佳答案

您的 docker 文件运行 npm i hapi -g,因此您在容器上全局安装 hapi,但我从未看到您在工作目录上运行 npm i。所以我猜你的应用程序将无法在 node_modules 中找到任何本地依赖项。

我建议您尝试在 docker 文件中的 WORKDIR/usr/src/app/backend 行之后添加 RUN npm i

关于node.js - Docker 无法从 package.json 文件安装依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53608296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com