errorvite:将VITE添加到docker

问题描述 投票:0回答:1

I在我的React项目中安装了Vite并设置了Docker,但是当构建容器时,我会收到错误:SH:1:VITE:找不到。我不明白为什么会发生这种情况,因为Vite已安装在项目中。

在添加VITE之前,我的项目没有错误。 package.json文件看起来像这样:

"scripts": { "start": "WATCHPACK_POLLING=true react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }
我服用的步骤:

1。我使用命令在项目中安装了Vite:

npm install vite

2。我在package.json中更新了脚本:

"scripts": { "dev": "vite", "build": "vite build", "serve": "vite preview" }, "devDependencies": { "react-refresh": "^0.16.0", "vite": "^6.0.11" }

3。我创建了vite.config.js配置文件:

import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()] });

4。我更新了dev.dockerfile,现在看起来像这样:

FROM node:latest RUN mkdir /app WORKDIR /app COPY package*.json ./ RUN npm install COPY . . CMD ["npm", "run", "dev"]

5。在docker-compose-dev.yml中,我配置了前端部分:

frontend: build: context: ./frontend dockerfile: dev.Dockerfile volumes: - .env:/app/.env - ./frontend:/app - /app/node_modules env_file: - .env depends_on: backend: condition: service_started

6。构建和使用命令启动容器时

docker compose -f docker-compose-dev.yml up --build 我有以下错误:

sh: 1: vite: not found


请让我知道您是否需要更多代码或其他详细信息来帮助诊断问题。 enter image description here 您的软件包在

vite

中列出。也许您已经将环境设置为

devDependencies
reactjs docker docker-compose dockerfile vite
1个回答
0
投票
production

),这就是为什么不安装Dev软件包的原因。

要修复它,您可以:
to以这样的部分,
NODE_ENV

npm install
或明确告诉

vite

用标志安装所有软件包。

    dependencies
  1. by设置
    "scripts": { "dev": "vite", "build": "vite build", "serve": "vite preview" }, "dependencies": { "vite": "^6.0.11" }, "devDependencies": { "react-refresh": "^0.16.0" }
    npm
  2. 将在您的
--production=false
文件中安装所有软件包,无论其值是什么。
    
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.