我正在使用node-pg-migrate
,它对pg
具有对等依赖关系。来自库package.json
文件
"peerDependencies": {
"pg": "^4.3.0"
},
我正在尝试使用以下DockerFile
在docker中运行该应用程序FROM node:latest
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Copy .env file
# Bundle app source
COPY . /usr/src/app
RUN cat package.json
EXPOSE 8000
安装库后出现以下错误
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
npm WARN node-pg-migrate@0.0.10 requires a peer of pg@^4.3.0 but none was installed.
npm WARN 42EXP@1.0.0 No description
npm WARN 42EXP@1.0.0 No repository field.
npm info ok
奇怪的是,我正在使用另一个库pg-promise
,它也依赖于pg
。但它似乎不会导致错误
这是pg-promise
package.json文件的片段
"dependencies": {
"pg": "5.1",
"spex": "1.x",
"pg-minify": "0.3",
"manakin": "^0.4.6"
},
如您所见,pg-promise
具有pg
作为其依赖关系,而node-pg-migrate
似乎将pg
指定为其对等关系。
问题是,我可以看到pg实际上是通过pg-promise
这是安装所有库后npm输出的快照
+-- UNMET PEER DEPENDENCY pg@6.1.0
+-- pg-promise@5.3.2
| +-- manakin@0.4.6
| +-- pg@5.1.0
| | `-- pgpass@0.0.6
| +-- pg-minify@0.3.3
| `-- spex@1.0.17
所以pg确实已安装..但看起来node-pg-migrate
仍无法找到该库。
node | > 42EXP@1.0.0 migrate /usr/src/app
node | > pg-migrate up
node |
node | module.js:457
node | throw err;
node | ^
node |
node | Error: Cannot find module 'pg'
node | at Function.Module._resolveFilename (module.js:455:15)
node | at Function.Module._load (module.js:403:25)
node | at Module.require (module.js:483:17)
node | at require (internal/module.js:20:19)
node | at Object.<anonymous> (/usr/local/lib/node_modules/node-pg-migrate/lib/db.js:5:10)
node | at Module._compile (module.js:556:32)
node | at Object.Module._extensions..js (module.js:565:10)
node | at Module.load (module.js:473:32)
node | at tryModuleLoad (module.js:432:12)
node | at Function.Module._load (module.js:424:3)
我尝试通过更改Dockerfile来全局安装pg-migrate
库以及将pg
作为独立库安装
FROM node:latest
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm cache clean
RUN npm install -g node-pg-migrate
RUN npm install --save pg
RUN npm install
# Copy .env file
# Bundle app source
COPY . /usr/src/app
RUN cat package.json
EXPOSE 8000
但无论我做什么,我似乎仍然会得到同样的错误。还有什么我可以尝试的吗?
答案 0 :(得分:1)
我将"pg":"^4.3.0"
添加到package.json中,它现在似乎正在运行。看起来pg-migrate
会查找pg