SWC插件不起作用 / 我编译的任何插件都会破坏Next.js。

huangapple go评论81阅读模式
英文:

SWC plugins not working / Any plugin I compile breaks Next js

问题

The Next.js框架使用SWC编译器而不是Babel。

我需要为SWC编写一个插件。一切都运行正常,但发生了一些事情。现在,我在我的计算机上编译的任何插件在Next.js中都无法工作。

我在SWC的GitHub上多次提到了这个问题。SWC的开发人员说了一些难以理解的话,但似乎除了我之外,对每个人都有效。

我将在下面留下所有关于此问题的GitHub讨论的链接。那里有错误的文本和所有数据。

我不写代码。我正在安装SWC的入门示例

另外,我要注意我尝试过很多不同版本的Rust、swc_core和swc_cli。每次都会导致Next.js崩溃。我还尝试在Windows虚拟机和Ubuntu上进行此操作。我真的需要帮助,帮助我弄清楚为什么这不起作用,即使我降级swc的版本。

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

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

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


要重现带有错误的最小示例,您需要按照以下步骤进行操作

  1. 下载并安装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

安装Next.js,将插件放在根文件夹中,并在配置文件(next.config.js)中包含它:

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

module.exports = nextConfig

辅助链接:

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

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

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

英文:

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

答案1

得分: -1

问题已通过SWC和Next.js的更新解决。

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

英文:

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

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

huangapple
  • 本文由 发表于 2023年5月7日 22:26:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定