vite4生产环境打包报错NODE_ENV=production is not supported in the .env file.

vue3+vite4生产环境production打包报错:

NODE_ENV=production is not supported in the .env file. Only NODE_ENV=development is supported to create a development build of your project. If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.

在这里插入图片描述
大致意思就是:
NODE_ENV=.ENV文件中不支持生产。仅支持NODE_ENV=开发来创建项目的开发构建。如果需要设置process.env.NODE_env,则可以在Vite配置中进行设置。
**

解决办法:vite降级版本3+

**
如果有警告

build.terserOptions is specified but build.minify is not set to use Terser. Note Vite now defaults to use esbuild for minification. If you still prefer Terser, set build.minify to "terser".

那就把vite.config.js里面的minify换成:terser(别忘记install下载了)
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45324044/article/details/128497307
env