create-react-app-swc icon indicating copy to clipboard operation
create-react-app-swc copied to clipboard

Failed to compile

Open Remeic opened this issue 2 years ago • 3 comments

Hi, i have this issue:

Failed to compile.
./src/index.tsx
TypeError: this.getOptions is not a function

craco-swc version: ^0.5.1 typescript version: ~4.0.8 react version: ^16.14.0 react-app-rewired ^2.1.8 Os: windows

craco config:

const CracoSwcPlugin = require('craco-swc');

module.exports = {
  plugins: [
    {
      plugin: CracoSwcPlugin,
      options: {
        swcLoaderOptions: {
          jsc: {
            externalHelpers: true,
            target: 'es2015',
            parser: {
              syntax: 'ecmascript',
              jsx: true,
              dynamicImport: true,
              exportDefaultFrom: true,
            },
          },
        },
      },
    },
  ],
};

Behaviour: start project in dev mode with craco start

Tell me if i have to add other information to solve the problem

Thanks in advance!

Remeic avatar May 03 '22 08:05 Remeic

Maybe this is related or can help? https://github.com/swc-project/swc/issues/4484

Remeic avatar May 03 '22 09:05 Remeic

I'm running into this same issue. I've followed the instructions (to change the version) that was mentioned in https://github.com/swc-project/swc/issues/4484. However that did not work.

Any suggestions are welcome.

slicejacob avatar May 11 '22 18:05 slicejacob

I've had a same error.

Try it like this. it works!

// craco.config.js
const CracoSwcPlugin = require('craco-swc');

module.exports = {
    plugins: [
        {
            plugin: {
                ...CracoSwcPlugin,
                overrideCracoConfig: ({ cracoConfig }) => {
                    if (typeof cracoConfig.eslint.enable !== 'undefined') {
                        cracoConfig.disableEslint = !cracoConfig.eslint.enable;
                    }
                    delete cracoConfig.eslint;
                    return cracoConfig;
                },
                overrideWebpackConfig: ({ webpackConfig, cracoConfig }) => {
                    if (
                        typeof cracoConfig.disableEslint !== 'undefined' &&
                        cracoConfig.disableEslint === true
                    ) {
                        webpackConfig.plugins = webpackConfig.plugins.filter(
                            (instance) => instance.constructor.name !== 'ESLintWebpackPlugin',
                        );
                    }
                    return webpackConfig;
                },
            },
            options: {
                swcLoaderOptions: {
                    jsc: {
                        externalHelpers: true,
                        target: 'es5',
                        parser: {
                            syntax: 'typescript',
                            tsx: true,
                            dynamicImport: true,
                            exportDefaultFrom: true,
                        },
                    },
                },
            },
        },
    ],
};

ref) https://jwchang0206.medium.com/make-create-react-app-faster-with-rust-6c75ffa8fdfd

min9nim avatar May 20 '22 04:05 min9nim