-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to support functions such as "optional chain" in QQ browser 10 or chrome 70 #5222
Comments
遇到同样的问题 |
同样的问题,请问现在有解决了嘛 |
尚未解决 |
好吧,谢谢答复 |
|
vite 在 dev 模式下转译 sfc 时没有为 esbuild 指定输出目标,导致始终被输出为 esnext 目前的 workaround 是把使用了新特性的代码从 .vue 文件抽离到单独的 .js/ts 文件里,并且在 vite.config.js 里添加
副作用是低于 es2020 时不能使用 |
这个不是正确的解决之道,请看最新的pr #5652 |
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import checker from 'vite-plugin-checker'
import vitePluginImp from 'vite-plugin-imp'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
plugins: [
react({
babel: {
plugins: ['@babel/plugin-proposal-optional-chaining'],
},
}),
}
})
|
大佬们,vue的有解决方案了吗 |
# vite.config.ts
esbuild: {
target: 'chrome70',
} |
感谢大佬 |
我也有这个问题~~~~~ |
我确认一下,这个问题是说 dev 时无法在 Chrome 70 下使用 optional chaining 语法?build 后没问题? |
Yes |
这个场景 Vite 核心应该不会支持。 这是因为 Vite 默认的假设就是 dev 环境是跑在最新的浏览器上的,esbuild 只是拿来处理非标准的语法。 不过引入第三方插件可以解决这个问题。 比如通过引入 import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import esbuild from 'rollup-plugin-esbuild'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
{
...esbuild({
target: 'chrome70',
// 如有需要可以在这里加 js ts 之类的其他后缀
include: /\.vue$/,
loaders: {
'.vue': 'js',
},
}),
enforce: 'post',
}
],
}) |
legacy 插件没有用是因为 legacy 插件是用来生成和处理 vite-babel-plugin 没有用是因为它只处理 build 场景:https://github.com/wingsico/vite-babel-plugin/blob/master/src/index.ts 理论上 |
我改了一下前面的示例配置。把兼容用的配置全都放在 |
没用的,继续报新的错误"Uncaught (in promise) TypeError: Cannot read properties of null (reading 'isCE')"" |
这个报错不是同一个问题:vuejs/core#4344 (comment) |
使用你给的配置才出现的这个问题,哈哈哈 |
已经找到问题,我另一个插件中使用了不同版本的vue导致的。最终确定您的这种增加一个plugin的方法可行。NB! |
Describe the bug
Invalid Babel configuration
// App.vue
// babel.config.js
// vite.config.ts
Reproduction
https://github.com/yangdan8/vite2-vue3-ts-demo
System Info
Used Package Manager
yarn
Logs
Uncaught SyntaxError: Unexpected token .
Validations
The text was updated successfully, but these errors were encountered: