英文:
ViteJS with docker cannot find module npm run install
问题
以下是您的Docker文件、Docker Compose和vite.config.ts的翻译部分:
Docker文件:
FROM node
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
CMD npm run dev
EXPOSE 4000
ENV NODE_ENV development
Docker Compose:
version: '3.8'
services:
app:
build: .
container_name: train_vite
working_dir: /app/
ports:
- "4000:4000"
volumes:
- ./:/var/www/html/app
command:
- npm run install
- npm run dev
environment:
NODE_ENV: development
vite.config.ts:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
watch: {
usePolling: true,
},
host: true,
strictPort: true,
port: 4000
}
})
如果您有其他问题或需要进一步的帮助,请随时告诉我。
英文:
with my Docker file
FROM node
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
CMD npm run dev
EXPOSE 4000
ENV NODE_ENV development
and docker compose
version: '3.8'
services:
app:
build: .
container_name: train_vite
working_dir: /app/
ports:
- "4000:4000"
volumes:
- ./:/var/www/html/app
command:
- npm run install
- npm run dev
environment:
NODE_ENV: development
and vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server:{watch:{
usePolling:true,
},
host:true,
strictPort:true,
port:4000
}
})
throws an error like this
the command I run is
docker compose up
I try to run a docker image with the app folder linked to the docker folder (volume) to see the changes on live.
答案1
得分: 1
一个单独的 command
可以在组合定义中指定为字符串:
"/run/this/command witharg"
或者是命令及其参数的数组。
[ "/run/this/command", "witharg" ]
现有的定义尝试执行一个名为 npm run install
的二进制文件,并带有参数 npm run dev
。
将示例更新为字符串:
version: '3.8'
services:
app:
build: .
container_name: train_vite
working_dir: /app/
ports:
- "4000:4000"
volumes:
- ./:/var/www/html/app
command: "npm run dev"
或者作为数组
command: [ "/usr/local/bin/npm", "run", "dev" ]
要在启动时运行多个命令,构建需要在容器中有一个脚本,然后将该脚本用作 command
或 entrypoint
。
英文:
A single command
can be specified in a compose definition as a string:
"/run/this/command witharg"
or an array of the command and its arguments.
[ "/run/this/command", "witharg" ]
The existing definition is attempting to execute a binary called
npm run install
with the argument npm run dev
Updating the example as a string:
version: '3.8'
services:
app:
build: .
container_name: train_vite
working_dir: /app/
ports:
- "4000:4000"
volumes:
- ./:/var/www/html/app
command: "npm run dev"
or as an array
command: [ "/usr/local/bin/npm", "run", "dev" ]
To run multiple commands at startup, the build would need a script in the container and that script used as a command
or entrypoint
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论