带有 preset-env(无选项)和 preset-typescript 的 Babel 表示 "Missing class properties transform"。为什么?
Babel with preset-env (no options) and preset-typescript says "Missing class properties transform". Why?
我有一个相当简单的 Babel 配置:
{
presets: [
[
'@babel/preset-typescript',
{
isTSX: true,
allExtensions: true,
allowNamespaces: true,
onlyRemoveTypeImports: true,
},
],
['@babel/preset-env', {}],
],
plugins: ['@babel/plugin-transform-react-jsx'],
},
这将在我的 Webpack 设置中传递给 babel-loader
。然后在构建时出现如下错误:
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
不是应该处理 class 字段之类的基本事情吗?
您需要将 "@babel/plugin-proposal-class-properties" 添加到您的插件配置中。 AFAIK,Babel 预设不会自行完成。
我有一个相当简单的 Babel 配置:
{
presets: [
[
'@babel/preset-typescript',
{
isTSX: true,
allExtensions: true,
allowNamespaces: true,
onlyRemoveTypeImports: true,
},
],
['@babel/preset-env', {}],
],
plugins: ['@babel/plugin-transform-react-jsx'],
},
这将在我的 Webpack 设置中传递给 babel-loader
。然后在构建时出现如下错误:
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
不是应该处理 class 字段之类的基本事情吗?
您需要将 "@babel/plugin-proposal-class-properties" 添加到您的插件配置中。 AFAIK,Babel 预设不会自行完成。