1

我正在使用 craco 并试图弄清楚如何配置 jsx。我不断收到以下错误

Support for the experimental syntax 'jsx' isn't currently enabled (4:17):

他们建议我添加 `babel/preset-react 或使用 @babel/plugin-syntax-jsx 到插件部分以启用解析,但我不确定如何做到这一点。

为了澄清,我正在尝试使用src我的 react-app 根目录之外的文件夹

craco.config.js

module.exports = {
  webpack: {
    alias: {},
    plugins: {
      add: [] /* An array of plugins */,
      remove:
        [] /* An array of plugin constructor's names (i.e. "StyleLintPlugin", "ESLintWebpackPlugin" ) */,
    },
    configure: {
      /* Any webpack configuration options: https://webpack.js.org/configuration */
    },
    configure: (webpackConfig, { env, paths }) => {
      console.log("WEBPACK");
      console.log(webpackConfig);
      webpackConfig.entry =
        "C:\\Users\\danie\\Desktop\\Code\\JS\\npm_packages\\source\\src\\index.js";
      return webpackConfig;
    },
  },
  babel: {
    presets: [],
    plugins: [],
    loaderOptions: (babelLoaderOptions, { env, paths }) => {
      console.log("BABEL");
      console.log(babelLoaderOptions);
      return babelLoaderOptions;
    },
  },
};

4

1 回答 1

0

通过将预设添加到我的配置文件来解决我的问题

craco.config.js

 babel: {
    presets: ['@babel/preset-react'],
    // plugins: [],
    loaderOptions: (babelLoaderOptions, { env, paths }) => {
      console.log("BABEL");
      console.log(babelLoaderOptions);
      return babelLoaderOptions;
    },
  },
于 2021-08-27T23:16:37.327 回答