首页 > 解决方案 > create-react-app (TypeScript) .babelrc throwIfNamespace=true 设置

问题描述

以为这很简单,但事实并非如此。我使用最新的 create-react-app 生成了一个简单的应用程序。添加<gcse:search>标签并获得以下信息:

Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can turn on the 'throwIfNamespace' flag to bypass this warning.
  16 |         return (
  17 |             <div className="comptext">
> 18 |                 <gcse:search defaultToRefinement="mostly-center"></gcse:search>
     |                  ^
  19 |             </div>
  20 |         );

.babelrc 是:

{
    "presets": [
        [
            "@babel/preset-react",
            {
                "throwIfNamespace": false
            }
        ]
    ]
}

我尝试了多个 .babelrc 配置,package.json 中的“babel”键,甚至尝试包括 .bablerc.js。没变

如果可能的话,我宁愿不弹出这个。

我错过了什么?

标签: javascriptreactjstypescriptbabeljscreate-react-app

解决方案


您需要按如下方式设置:

"throwIfNamespace"`: false in file `@babel/preset-react/index.js


推荐阅读