vite打包后的项目在有的浏览器上报错globalThis is not defined 安装依赖 @vitejs/plugin-legacy 2.x版本,需要vite3.x版本 yarnadd@vitejs/plugin-legacy-D 修改vite.config.js相配置 importlegacyfrom'@vitejs/plugin-legacy';exportdefaultdefineConfig({build: {target:'es2015', },plugins: [legacy({targets...
如果确实需要这样做,你可以考虑使用 @vitejs/plugin-legacy 之类的插件来处理兼容性问题。 不过,在大多数情况下,最好的做法是避免在 Vite 项目中使用 CommonJS 语法。 5. 测试并验证解决方案 修改完代码后,运行项目以确保错误已被解决,并且功能正常运行。你可以使用以下命令来启动 Vite 开发服务器: bash npm run...
When adding the Vite plugin @vitejs/plugin-legacy and trying to build using nuxt build I get an error. The error does not happen when using a clean Vite project, so I guess it is related to Nuxt. Additional context No response Logs ERROR [vite:terser] _require2 is not defined 11:12...
在安装了@vitejs/plugin-legacy版本2.x后,运行npm run build进行打包,报错: Cannot destructureproperty'renderBuiltUrl'of'config.experimental'asitisundefined 原因:plugin-legacy版本为2.x后,vite版本需要为3.x版本 "devDependencies": {"@vitejs/plugin-legacy":"^2.1.0","vite":"^3.1.0", ... }...
legacy({ targets: ['chrome 49'], modernPolyfills: ['es.global-this'],// 解决浏览器端 globalThis is not defined 报错 }), ] }) 复制代码 踩了这么多坑,你可能会问,后悔在新项目里面用 vue3 了吗?我的答案是没有。对于一个不太重的新项目,你又想尝试卷卷 vue3,我个人觉得或许是个不错的选择...
global is not defined ReferenceError: global is not defined at node_modules/randombytes/browser.js (http://localhost:3000/node_modules/.vite/simple-peer.js?v=10be15c3:2351:18) at __require (http://localhost:3000/node_modules/.vite/chunk-UNANNA3Z.js?v=10be15c3:38:50) at node_modules...
i install legacy plugin in pure vite project and don't see this problem. i think nuxt problem! Additional context No response Logs Uncaught ReferenceError: System is not defined`entry-legacy.4e3349cb.js:1:12341` xtoolkit added pending triage ...
老项目中不可避免会经常用到require(),在vite中会编译不通过,显示require is not defined,这个时候把require改成import就可以(有可能是vite仅支持ESM不支持CJS) 官网的@vitejs/plugin-legacy插件为打包后的文件提供传统浏览器兼容性支持,但是在dev的时候好像不起作用 ...
因为 vite 是基于现代浏览器支持的 ESM 机制,所以构建后文件模块仍是 ESM,如果需要支持旧版浏览器就需要使用 @vitejs/plugin-legacy。 安装及使用 npm i -D @vitejs/plugin-legacy // vite.config.ts import { defineConfig } from 'vite' import legacy from '@vitejs/plugin-legacy' export default ...
1.首先安装插件:npm i @vitejs/plugin-legacy -D 2.然后配置vite.config.js import legacyPlugin from '@vitejs/plugin-legacy'; export default defineConfig({ plugins: [ legacyPlugin({ targets: ['chrome 52'], // 需要兼容的目标列表,可以设置多个 ...