2

I'm trying to move from babel to swc for compiling and bundling a react component library but I have trouble with the configuration.

When I run npm run spack, I get the following error:

thread '<unnamed>' panicked at 'internal error: entered unreachable code: module item found but is_es6 is false: ExportNamed(NamedExport { span: Span { lo: BytePos(954874), hi: BytePos(954914), ctxt: #0 }, specifiers: [Named(ExportNamedSpecifier { span: Span { lo: BytePos(954883), hi: BytePos(954890), ctxt: #0 }, orig: Ident(Ident { span: Span { lo: BytePos(954883), hi: BytePos(954890), ctxt: #4141 }, sym: Atom('default' type=static), optional: false }), exported: Some(Ident(Ident { span: Span { lo: BytePos(954883), hi: BytePos(954890), ctxt: #194 }, sym: Atom('default' type=static), optional: false })), is_type_only: false })], src: Some(Str { span: Span { lo: BytePos(954898), hi: BytePos(954913), ctxt: #0 }, value: Atom('./FormControl' type=dynamic), raw: Some(Atom(''./FormControl'' type=dynamic)) }), type_only: false, asserts: None })', crates/swc_bundler/src/bundler/chunk/cjs.rs:142:29

What I get from this error is that he fails to bundle React components. I can't find the is_es6 configuration mentioned in the error so I'm not sure how to solve this. I tried rereading the doc of swc without any success. The module part of the config doesn't seem to solve my problem.

Here is my working tree:

.
├── jest.config.ts
├── package-lock.json
├── package.json
├── spack.config.js
└── src
    ├── components
    │   ├── FiltersBar
    │   │   ├── FiltersBar.test.tsx
    │   │   ├── FiltersBar.tsx
    │   │   ├── __snapshots__
    │   │   │   └── FiltersBar.test.tsx.snap
    │   │   └── index.ts
    │   └── index.ts
    ├── index.ts
    └── libraries
        ├── helpers
        │   ├── helpers.test.ts
        │   ├── helpers.ts
        │   └── index.ts
        └── index.ts

Here is my .swcrc file:

{
    "jsc": {
      "target": "es2021",
      "parser": {
        "syntax": "typescript"
      }
    },
    "module": {
      "type": "commonjs"
    }
  }

I'm pretty new to all this stuff so please bear with me :)

JulienR.
  • 33
  • 3

0 Answers0