英文:
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
要重现带有错误的最小示例,您需要按照以下步骤进行操作
- 下载并安装Rust https://www.rust-lang.org/learn/get-started
- rustup default nightly-2023-03-20
- cargo install swc_cli
- swc plugin new --target-type wasm32-wasi my-first-plugin
- cd my-first-plugin
- rustup target add wasm32-wasi
- 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
- download and install rust https://www.rust-lang.org/learn/get-started
- rustup default nightly-2023-03-20
- cargo install swc_cli
- swc plugin new --target-type wasm32-wasi my-first-plugin
- cd my-first-plugin
- rustup target add wasm32-wasi
- 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
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论