简体   繁体   English

带有预设环境(无选项)和预设打字稿的 Babel 说“缺少 class 属性转换”。 为什么?

[英]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.

相关问题 摩卡说“错误:意外的令牌{”(使用@babel/preset-env) - Mocha says "ERROR: Unexpected token {" (using @babel/preset-env) 汇总+ @ babel / preset-env + @ babel / polyfill - Rollup + @babel/preset-env + @babel/polyfill 与 @babel/env 和 @babel/preset-env 之间的 babel 预设配置混淆 - confused with babel preset configs between @babel/env and @babel/preset-env TypeScript 编译器是否具有与 babel preset-env 相同的浏览器支持 - Does the TypeScript complier have the same browser support as I would have with babel preset-env @babel/preset-env 字段中的“modules:auto”是什么意思? - what does the "modules:auto" means in @babel/preset-env field? @babel/preset-env 不从 package.config 读取浏览器列表 - @babel/preset-env not reading browserslist from package.config 模块构建失败找不到模块'@babel/preset-env' - Module build failed Cannot find module '@babel/preset-env' @babel/preset-env 版本 7 未转换 null-coalescing 运算符 - @babel/preset-env version 7 not transforming the null-coalescing operator 在节点应用程序中使用 babel/preset-env 启用扩展运算符 - Enable spread operator using babel/preset-env in node application 使用@ babel / preset-typescript从环境TypeScript模块中消耗枚举吗? - Consume enum from ambient TypeScript module using @babel/preset-typescript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM