繁体   English   中英

未能加载 SWC 二进制文件

[英]Failed to load SWC binary

尝试使用 Next.js npm run dev命令时显示error - failed to load SWC binary see more info here: https://nextjs.org/docs/messages/failed-loading-swc.

PS D:\web-development\new-project\explore> npm run dev

> dev     
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Error: The specified module could not be found.
\\?\D:\web-development\new-project\explore\node_modules\@next\swc-win32-x64-msvc\next-swc.win32-x64-msvc.node
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1179:18)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at loadNative (D:\web-development\new-project\explore\node_modules\next\dist\build\swc\index.js:84:28)
    at loadBindings (D:\web-development\new-project\explore\node_modules\next\dist\build\swc\index.js:41:32)
    at async Object.isWasm (D:\web-development\new-project\explore\node_modules\next\dist\build\swc\index.js:146:20)
    at async D:\web-development\new-project\explore\node_modules\next\dist\build\webpack\loaders\next-swc-loader.js:62:178 {
  code: 'ERR_DLOPEN_FAILED'
}
error - Failed to load SWC binary, see more info here: https://nextjs.org/docs/messages/failed-loading-swc
PS D:\web-development\new-project\explore>

我解决它的方法。

一开始,我按照错误给出的文档链接进行操作。

错误 - 无法加载 SWC 二进制文件,请在此处查看更多信息: https://nextjs.org/docs/messages/failed-loading-swc

Go 到此链接https://nextjs.org/docs/messages/failed-loading-swc并阅读此文档。

然后 go 到这个链接https://swc.rs/ 下载 SWC 二进制预编译并添加 Transpile JavaScript 文件。

# Download prebuilt binaries
npm i -D @ swc / cli @ swc / core

# Transpile JavaScript file and emit to stdout
npx swc ./file.js

然后再将 go 指向此链接https://nextjs.org/docs/messages/failed-loading-swc并在 next.config.js 旁边创建.babelrc 文件。 将 doc 中的代码插入 .babelrc 文件中。

{
    "presets": ["next / babel"]
}

然后“npm run dev”就可以了。

如果从 git 克隆项目后发生错误,您可以尝试我的步骤

当我从旧仓库克隆项目时,我在 windows 11 中遇到了同样的问题。 首先我尝试删除 yarn.lock 和 node_modules,然后再次安装依赖项,但它不起作用。

几分钟后,我发现是因为我有权限问题。 我以管理员身份安装 git,因此,我从 choco 中删除了 git

choco uninstall git

我从 git 单片机安装 git。 你可以在这里下载https://git-scm.com/downloads

之后我克隆项目,运行纱线,它就像一个魅力。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM