swc icon indicating copy to clipboard operation
swc copied to clipboard

Cannot use webpack's resolve.alias

Open xxoojs opened this issue 5 years ago • 17 comments

Cannot use webpack's resolve.alias

resolve: { '@': resolve('source') }

Error: failed to parse config file: data did not match any variant of untagged enum Rc @ multi

xxoojs avatar Jan 15 '20 07:01 xxoojs

Can you share your config code related to swc-loader?

kdy1 avatar Jan 15 '20 07:01 kdy1

webpack config:

{
        test: /\.[t|j]sx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'swc-loader',
        include: [resolve('src'), resolve('source'), resolve('test')],
 }

.swcrc:

{
  "jsc": {
    "transform": {
      "react": {
        "pragma": "React.createElement",
        "pragmaFrag": "React.Fragment",
        "throwIfNamespace": true,
        "development": false,
        "useBuiltins": false
      }
    },
    "parser": {
      "syntax": "ecmascript",
      "jsx": true,
      "classProperty": true,
      "decorators": true,
      "optionalChaining": true
    }
  }
}

xxoojs avatar Jan 15 '20 08:01 xxoojs

@xxoojs Can you share your config file related to resolve? I'm trying to reproduce it, but I don't know where I should put "@": path.resolve("source").

kdy1 avatar Jan 17 '20 03:01 kdy1

@kdy1 maybe this?

{
        test: /\.[t|j]sx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'swc-loader',
        include: [resolve('src'), resolve('source'), resolve('test')],
        resolve: {
          alias: {
            "@": path.resolve("source")
          }
       }
 }

Austaras avatar Jan 31 '20 17:01 Austaras

@Austaras I'll try to fix it.

kdy1 avatar Jan 31 '20 22:01 kdy1

resolve is a top-level key in Webpack; the config above should be something like:

module.exports = {
  module: {
    rules: [
      {
        test: /\.[t|j]sx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'swc-loader',
      }
    ],
  },
  resolve: {
    alias: {
      "@": path.resolve("whatever"),
    },
  },
};

FWIW, it works locally when putting resolve at the correct level.

leebenson avatar Mar 26 '20 20:03 leebenson

Is this issue still open for contributors?

Bruce-Hopkins avatar Sep 23 '22 15:09 Bruce-Hopkins

Yes

kdy1 avatar Sep 23 '22 15:09 kdy1

Yes

Great. I want to contribute here, but this would be my first contribution.

I read over the CONTRIBUTING.md file but I'm not familiar with the codebase. Which files would need to be changed? Could you help, or guide me to where I can find the information? Thank you.

Bruce-Hopkins avatar Sep 26 '22 06:09 Bruce-Hopkins

I don't know where to start. https://rustdoc.swc.rs/swc/ may help

kdy1 avatar Sep 26 '22 10:09 kdy1

When I use vanilla JavaScript this seems to work, Maybe this was fixed or this is only an issue on with React

Bruce-Hopkins avatar Oct 09 '22 17:10 Bruce-Hopkins

@kdy1 Is there any progress on this issue?

codewizardTM avatar Nov 21 '23 10:11 codewizardTM

Is there any update or work around for this? Experiencing this issue currently.

swalker326 avatar Dec 13 '23 19:12 swalker326

We are open to accept contributions / PRs, otherwise unless issue explicitly updates there are no updates.

kwonoj avatar Dec 13 '23 19:12 kwonoj

If it is of value to anyone else trying to trouble shoot this. I have a reproduction repo.

https://github.com/swalker326/rspack-module-federation

I only saw the error once I installed @module-federation/utilities I'm kinda lost in where it is actually coming from but trying my best, lol.

swalker326 avatar Dec 13 '23 19:12 swalker326

If it is of value to anyone else trying to trouble shoot this. I have a reproduction repo.

https://github.com/swalker326/rspack-module-federation

I only saw the error once I installed @module-federation/utilities I'm kinda lost in where it is actually coming from but trying my best, lol.

This is unrelated to swc, let's move the issue to https://github.com/web-infra-dev/rspack

Boshen avatar Dec 14 '23 04:12 Boshen

https://github.com/swc-project/swc/issues/8486 working for me

kumv-net avatar Jan 08 '24 20:01 kumv-net