0

我有一个相当简单的 Babel 配置:

            {
              presets: [
                [
                  '@babel/preset-typescript',
                  {
                    isTSX: true,
                    allExtensions: true,
                    allowNamespaces: true,
                    onlyRemoveTypeImports: true,
                  },
                ],
                ['@babel/preset-env', {}],
              ],
              plugins: ['@babel/plugin-transform-react-jsx'],
            },

这是babel-loader在我的 Webpack 设置中传递的。然后我在构建时收到如下错误:

ERROR in ./store/state/AppState.ts
Module build failed (from ../node_modules/babel-loader/lib/index.js):
SyntaxError: /home/trusktr/src/my-project/src/store/state/AppState.ts: Missing class properties transform.
  25 | 
  26 | export class AppState implements State<string> {
> 27 |   static Key = 'AppState'

这是版本:

❯ npm ls @babel/core @babel/preset-env @babel/preset-typescript @babel/plugin-transform-react-jsx babel-loader
my-project@1.0.0 /home/trusktr/src/my-project
├── @babel/core@7.9.0 
├── @babel/plugin-transform-react-jsx@7.9.4 
├── @babel/preset-env@7.9.5 
├── @babel/preset-typescript@7.9.0 
└── babel-loader@8.1.0

任何想法为什么会发生这种情况?不preset-env应该处理类字段之类的基本事情吗?

4

1 回答 1

0

您需要将“@babel/plugin-proposal-class-properties”添加到您的插件配置中。AFAIK,Babel 预设不是自己做的。

于 2020-10-26T09:24:24.757 回答