这是我的babe.config.js:
module.exports = {
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
modules: false,
},
],
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'styled-components',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
],
env: {
production: {
only: ['app'],
plugins: [
'lodash',
'transform-react-remove-prop-types',
'@babel/plugin-transform-react-constant-elements',
],
},
test: {
plugins: [
'@babel/plugin-transform-modules-commonjs',
'dynamic-import-node',
],
},
},
};
现在我得到了这个错误:
Support for the experimental syntax 'optionalChaining' isn't currently enabled (39:37):
37 |
38 | try {
> 39 | console.log('APP VERSION', process?.env?.VERSION, process?.env?.ENVIRONMENT);
| ^
40 | } catch (e) {
41 | console.error(e);
42 | }
Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.
所以从根本上说,巴别塔忽略了@babel/plugin-proposal-optional-chaining
,这个被认为是用来处理optionalChaining的插件
发布于 2021-06-11 04:48:10
我通过简单地将@babel/core
升级到最新版本解决了这个问题。
https://stackoverflow.com/questions/67906964
复制相似问题