Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run time error while using @formatjs/swc plugin #8121

Closed
saidarshan27 opened this issue Oct 15, 2024 · 3 comments
Closed

run time error while using @formatjs/swc plugin #8121

saidarshan27 opened this issue Oct 15, 2024 · 3 comments
Assignees

Comments

@saidarshan27
Copy link

saidarshan27 commented Oct 15, 2024

I am using rspack version 1.0.10 and swc/core version 1.7.0 and formatjs/swc-plugin version 1.5.16.

And here is my javascript loader configuration:

const js = {
  test: /\.js(x)?$/,
  exclude: [
    /node_modules/,
    path.join(config.root, config.paths.src, 'web', 'javascripts/vendors/'),
  ],
  loader: 'builtin:swc-loader',
  options: {
    jsc: {
      parser: {
        syntax: 'ecmascript',
        jsx: true,
      },
      transform: {
        react: {
          runtime: 'automatic',
          development: config.env === 'production',
          refresh: config.env === 'production',
        },
      },
      experimental: {
        plugins: [
          [
            '@formatjs/swc-plugin',
            {
              overrideIdFn: '[sha512:contenthash:base64:6]',
              ast: true,
            },
          ],
        ],
      },
    },
    type: 'javascript/auto',
    env: {
      targets: 'Chrome >= 48',
    },
  },
};

I am getting a run time error which as below:

Image

I have followed the versions according to this webpage https://plugins.swc.rs/versions/range/16

Please help me in how I can use @formatjs/swc-plugin with rspack.

Thank you

Copy link
Contributor

Hello @saidarshan27, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

@saidarshan27
Copy link
Author

saidarshan27 commented Oct 15, 2024

Node - v18.12.0;
yarn - 1.22.19;
@rspack/core - 1.0.10;
@rspack/cli - 1.0.8;
@swc/core - 1.7.0;
@formatjs/swc-plugin - 1.5.16;

Here is a reproduction demo:

https://github.com/saidarshan27/rspack-formatjs-test

Please clone it and run

yarn install 
yarn start 

You should encounter an error like:

ERROR in ./src/javascripts/index/index.js
  × Module build failed:
  ├─▶   × Cannot compile plugin binary
  │   
  ╰─▶ WebAssembly translation error: Error when converting wat: expected `(`
           --> <anon>:1:1
            |
          1 | "use strict";
            | ^

Thank you.

@saidarshan27
Copy link
Author

I was using the wrong plugin. I used formatjs/swc-plugin-experimental instead of formatjs/swc-plugin.

formatjs/swc-plugin was written in JS and SWC has deprecated using JS plugins long back.
formatjs/swc-plugin-experimental instead is written in WASM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants