问题描述
我有一个本地正在使用的npm模块,它是客户端应用程序中的依赖项。
I have an npm module I'm working on locally that is a dependency in a client app.
目录结构基本上如下:
/app
/client
/src
App.js
package.json
Dockerfile.dev
/shared
/contexts
package.json
test.js
/hooks
我的 package.json
如下:
{
"name": "web",
"version": "0.1.0",
"private": true,
"dependencies": {
"contexts": "file:../shared/contexts",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-scripts": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
将以下内容导入 client / src / App。 js
:
import { testImport } from 'contexts/test';
当我运行 npm start
时按预期工作。
Works as expected when I run npm start
.
我遇到的问题与运行有关:
The issue I'm running into is with running:
docker build -t sockpuppet/testapp -f Dockerfile.dev .
失败,并出现错误:
npm ERR! Could not install from "../shared/contexts" as it does not contain a package.json file.
这是Dockerfile.dev
Here is he Dockerfile.dev
FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
我应该如何
还要在 COPY
中添加如下内容: / shared
进入映像会生成 COPY失败:构建上下文之外的禁止路径:../shared/contexts()
错误:
Also, adding something like the following to COPY
the /shared
into the image generates a COPY failed: Forbidden path outside the build context: ../shared/contexts ()
error:
COPY ../shared ./
推荐答案
好的,这可行。我将 Dockerfile.dev
更改为以下内容:
Ok, this works. I changed my Dockerfile.dev
to the following:
FROM node:alpine
WORKDIR '/app'
COPY ./shared /shared
COPY ./web /app
RUN npm install
CMD ["npm", "run", "start"]
从基础项目目录(其中 / shared
和 / web
驻留),我运行:
From the base project directory (where /shared
and /web
reside), I run:
docker build -t sockpuppet/client -f ./web/Dockerfile.dev .
这篇关于本地npm依赖性“不包含package.json文件”。在docker build中,但是在npm start上运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!