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
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"react-refresh": "^0.16.0",
"vite": "^6.0.11"
}
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()]
});
FROM node:latest
RUN mkdir /app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
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
docker compose -f docker-compose-dev.yml up --build
我有以下错误:
sh: 1: vite: not found
请让我知道您是否需要更多代码或其他详细信息来帮助诊断问题。
您的软件包在
vite
中列出。也许您已经将环境设置为
devDependencies
production
),这就是为什么不安装Dev软件包的原因。
要修复它,您可以:
to以这样的部分,
NODE_ENV
npm install
或明确告诉vite
用标志安装所有软件包。
dependencies
by设置
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
"vite": "^6.0.11"
},
"devDependencies": {
"react-refresh": "^0.16.0"
}
,
npm
--production=false
文件中安装所有软件包,无论其值是什么。