Closed pasteusernamehere closed 2 years ago
不知道咋了,用了es7语法就不行,你的这个??是ES7语法, 我的用了?.和你发生的问题一样。。。。
yo, man, i encountered same problem, but i already solved i. The following methods:
add following config into the babel.config.js:
plugins: [ [ '@babel/plugin-proposal-optional-chaining' ], [ '@babel/plugin-proposal-nullish-coalescing-operator' ] ]
and just in case, maybe u need:
npm i @babel/plugin-proposal-nullish-coalescing-operator @babel/plugin-proposal-optional-chaining --save-dev
手动加 presets: [ ['@babel/preset-env'] ],也可以解决, 主要是更新了什么,以前不用配置啊
Can't reproduce with the given repo…
Same problem, existing projects using optional chaining operators running until 4.5.17 cannot be compiled in 4.5.18 anymore.
Oh, I got it. It's because IE 11 has reached end-of-life.
So the "not dead" query in .browserslistrc
excludes it.
You need to add an IE 11
line to the end of .browserslistrc
. Remove node_modules/.cache
. And then run the build again.
手动加 presets: [ ['@babel/preset-env'] ],也可以解决, 主要是更新了什么,以前不用配置啊
手动加了presets: [ ['@babel/preset-env'] ]
,问题依旧。
下面这个方法有效,但没想明白原因,按babel官方讲的这两个插件都是包含在@babel/preset-env
。
yo, man, i encountered same problem, but i already solved i. The following methods:
add following config into the babel.config.js:
plugins: [ [ '@babel/plugin-proposal-optional-chaining' ], [ '@babel/plugin-proposal-nullish-coalescing-operator' ] ]
and just in case, maybe u need:
npm i @babel/plugin-proposal-nullish-coalescing-operator @babel/plugin-proposal-optional-chaining --save-dev
@bwangs 这是因为 browserslist 前两天发布的新版本 4.21 里把 IE 11 列入了 dead 名单 https://github.com/browserslist/browserslist/blob/4.21.0/CHANGELOG.md#421 所以默认的 "not dead" 条件会把它排除在外。
而不包含 IE 11 的、满足 "> 1%, not dead, last 2 versions" 的所有浏览器,都支持最新的语法标准,所以 @babel/preset-env
不再需要转译 ??
。
至于这个 issue 里出现的报错,则是因为项目的依赖版本比较老,除了 Babel 以外,其他的工具比如 webpack 4 是不支持新语法的,所以如果 Babel 不再把代码转换好再输出给它们,它们就会报无法解析的错误。
I've posted a Twitter thread to explain the underlying issue here: https://twitter.com/haoqunjiang/status/1539857134317600769
@bwangs 不应该啊!你加的那两个也都是preset-env包含的,一个是?. 一个??语法转换插件么?
@sodatea 嗯,试了下加上IE11确实有效,想了下应该IE11退役导致babel不在转译了这个原因
@chinaxcy 这两个插件是这个两个转译功能。 这个解释应该就是原因。
@bwangs 这是因为 browserslist 前两天发布的新版本 4.21 里把 IE 11 列入了 dead 名单 https://github.com/browserslist/browserslist/blob/4.21.0/CHANGELOG.md#421 所以默认的 "not dead" 条件会把它排除在外。
而不包含 IE 11 的、满足 "> 1%, not dead, last 2 versions" 的所有浏览器,都支持最新的语法标准,所以
@babel/preset-env
不再需要转译??
。至于这个 issue 里出现的报错,则是因为项目的依赖版本比较老,除了 Babel 以外,其他的工具比如 webpack 4 是不支持新语法的,所以如果 Babel 不再把代码转换好再输出给它们,它们就会报无法解析的错误。
不锁死版本太可怕,很有可能时隔几年的项目跑都跑步起来了
@sodatea 致敬大佬 !
@ShuangDa1018 与版本无关,这个方法有效
Oh, I got it. It's because IE 11 has reached end-of-life. So the "not dead" query in
.browserslistrc
excludes it. You need to add anIE 11
line to the end of.browserslistrc
. Removenode_modules/.cache
. And then run the build again.
@ShuangDa1018 回退可以,我试过但是保证browserlist也回退到相应的版本
@bwangs 怎么和版本无关呢?这一天天的,迷糊的呢?
@chinaxcy 我的意思是和这个@vue/cli-plugin-babel
包的版本无关~_~
@bwangs 怎么和版本无关呢?这一天天的,迷糊的呢?
Oh, I got it. It's because IE 11 has reached end-of-life. So the "not dead" query in
.browserslistrc
excludes it. You need to add anIE 11
line to the end of.browserslistrc
. Removenode_modules/.cache
. And then run the build again.
This appears to be it @sodatea, good eye!
手动加 presets: [ ['@babel/preset-env'] ],也可以解决, 主要是更新了什么,以前不用配置啊 it work for me, Thx bro
Hello @sodatea
Is a fix for vue-cli@4 is planned ? Because a new project generated with this version breaks. I know that V5 is the current version but it can be great to fix v4.
In our company we have lots of v4 projects, it is just to know if we have to do a "permanant" fix or if the CLI will be patched.
Thans for the response.
@sodatea 牛啊牛啊
In our company we have lots of v4 projects, it is just to know if we have to do a "permanant" fix or if the CLI will be patched.
@Benoit-Vasseur I've just released 4.5.19 to add an upper limit of browser targets, to fix the ??
/ ?.
syntax support.
But for IE 11 support, we can't make the decision for the users, so if you still have to support IE in your projects, it must be manually specified in the browserslist configuration.
Version
4.5.18
Reproduction link
github.com
Environment info
Steps to reproduce
You can build the existing project via: npm run build:dev
When targeting @vue/cli-plugin-babel@4.5.17 the project builds without errors. Targeting @vue/cli-plugin-babel@4.5.18 produces compilation errors.
What is expected?
The expectation would be to compile without error.
What is actually happening?
Failed to compile with 1 error 11:59:22 a.m.
error in ./src/main.ts
Module parse failed: Unexpected token (18:41) File was processed with these loaders:
./node_modules/eslint-loader/index.js You may need an additional loader to handle the result of these loaders. | args[key] = value; | });
@ multi ./src/main.ts
I have stripped out pretty much everything in order to exhibit the behavior.
Background: We utilize main.ts to either launch our full app (TheShell) or to launch containerized components (inline or in new windows). I have removed all of the containerized components.