[英]Babel with preset-env (no options) and preset-typescript says “Missing class properties transform”. Why?
I've got a fairly simple Babel config:我有一个相当简单的 Babel 配置:
{
presets: [
[
'@babel/preset-typescript',
{
isTSX: true,
allExtensions: true,
allowNamespaces: true,
onlyRemoveTypeImports: true,
},
],
['@babel/preset-env', {}],
],
plugins: ['@babel/plugin-transform-react-jsx'],
},
This is being passed to babel-loader
in my Webpack setup.这将在我的 Webpack 设置中传递给
babel-loader
。 Then I get errors like the following when I build:然后我在构建时收到如下错误:
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'
Here's the versions:这是版本:
❯ 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
Any ideas why this happens?任何想法为什么会发生这种情况? Isn't
preset-env
suppose to handle basic things like class fields?是不是
preset-env
环境假设可以处理诸如 class 字段之类的基本内容?
You need to add "@babel/plugin-proposal-class-properties" to your plugins configuration.您需要将“@babel/plugin-proposal-class-properties”添加到您的插件配置中。 AFAIK, Babel presets does not do it by themselves.
AFAIK,Babel 预设不是自己做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.