1

The Next js framework uses the SWC compiler instead of Babel.

I need to write a plugin for SWC. Everything was working fine, but something happened. Now any plugin that I compile on my computer doesn't work in Next js.

I wrote about this many times in the SWC github. The SWC developers say something incomprehensible, but it seems that everything works for everyone except me.

I will leave links to all github discussions about this. There both the text of an error, and all data.

I don't write code. I'm installing the starter example from SWC

Separately, I note that I have tried a lot of versions of Rust, swc_core, swc_cli. Every time Next js breaks. I also tried doing this on a windows virtual machine and ubuntu. I really need help, help me understand why this is not working, even if I downgrade the swc version

https://github.com/swc-project/swc/issues/7381

https://github.com/swc-project/swc/issues/7386

https://github.com/swc-project/swc/discussions/7361


To reproduce a minimal example with an error you need to follow these steps

  1. download and install rust https://www.rust-lang.org/learn/get-started
  2. rustup default nightly-2023-03-20
  3. cargo install swc_cli
  4. swc plugin new --target-type wasm32-wasi my-first-plugin
  5. cd my-first-plugin
  6. rustup target add wasm32-wasi
  7. cargo build-wasi --release

Install next js, put the plugin in the root folder, and include it in the config(next.config.js):

const nextConfig = {
      experimental: {
        swcPlugins: [
            [require.resolve("./my_first_plugin.wasm"),{}]
        ],
  },
}

module.exports = nextConfig

Auxiliary links:

https://swc.rs/docs/plugin/ecmascript/getting-started

https://swc.rs/docs/plugin/publishing

https://nextjs.org/docs/pages/api-reference/create-next-app

Roman
  • 175
  • 2
  • 3
  • 15
  • So, which version of next.js and swc_core have you installed? – xamgore May 15 '23 at 10:14
  • @xamgore I installed next js - v13.3.1-canary.12, swc_core - 0.75.0, the problem started about 8 days ago. Plugins which I compiled earlier work and now. But any compilation now breaks next js – Roman May 15 '23 at 10:20
  • @xamgore Old plugins work in the latest version of next js. Please try to compile a starter instance of the plugin. I wonder if you will have the same problem – Roman May 15 '23 at 10:23
  • next v13.2.4 ~ v13.3.1 cannot execute SWC Wasm plugins, due to a bug of next-swc. Could you try [v13.4](https://nextjs.org/blog/next-13-4)? – xamgore May 15 '23 at 11:19
  • Could you share a link on how to compile a starter plugin? And what else do I need to install – xamgore May 15 '23 at 11:20
  • @xamgore The plugins I compiled 8 days ago work in both v13.3.1-canary.12 and 13.4. But now any plugin I compiled doesn't work. I added instructions to reproduce the issue to my question – Roman May 15 '23 at 13:23

1 Answers1

-1

The problem was solved with the update of SWC and Next js.

swc_cli - v0.91.42 next js - 13.4.3-canary.2

Roman
  • 175
  • 2
  • 3
  • 15