PageSourceSearch

https://rspack.rs/static/js/async/route-43347dae4abf.b408eeafe7.js

js rspack.rs collected 2026-10-02 02:42:35 UTC 15,375 bytes, 1 lines download raw bytes

1"use strict";(self.rspackChunkrspack_website=self.rspackChunkrspack_website||[]).push([["hd"],{Ob(s,e,r){r.r(e);var n=r("i"),a=r("fj"),i=r("V");function c(s){let e={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",li:"li",ol:"ol",p:"p",pre:"pre",span:"span",...(0,a.R)(),...s.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.h1,{id:"debugging",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#debugging",children:"#"}),"Debugging"]}),"\n",(0,n.jsxs)(e.h2,{id:"通过-vs-code-调试",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#通过-vs-code-调试",children:"#"}),"通过 VS Code 调试"]}),"\n",(0,n.jsxs)(e.ol,{children:["\n",(0,n.jsxs)(e.li,{children:["安装 ",(0,n.jsx)(e.code,{children:"go install github.com/go-delve/delve/cmd/dlv@latest"})]}),"\n",(0,n.jsxs)(e.li,{children:["安装 VS Code 扩展 ",(0,n.jsx)(e.a,{href:"https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer",rel:"noopener noreferrer",target:"_blank",children:"rust-analyzer"})," 和 ",(0,n.jsx)(e.a,{href:"https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb",rel:"noopener noreferrer",target:"_blank",children:"CodeLLDB"})]}),"\n",(0,n.jsxs)(e.li,{children:["通过执行 ",(0,n.jsx)(e.code,{children:"pnpm install && pnpm -w build:cli:dev"})," 构建 ",(0,n.jsx)(e.code,{children:"@rspack/cli"})," 和 napi binding"]}),"\n",(0,n.jsxs)(e.li,{children:["在 VS Code 的 ",(0,n.jsx)(e.code,{children:"Run and Debug"})," 栏中, 选择 ",(0,n.jsx)(e.code,{children:"Debug Rspack"})," 开始调试 ",(0,n.jsx)(e.code,{children:"@rspack/cli"})," 的启动过程。 该任务可以在 ",(0,n.jsx)(e.code,{children:".vscode/launch.json"})," 中配置,会同时启动 Node 和 Rust 的调试器。"]}),"\n"]}),"\n",(0,n.jsx)(i.Pq,{type:"note",title:"Note",children:(0,n.jsx)(e.p,{children:"\n其他工具集成的一般是 Rspack 的 release 版本,其中并不包含调试信息,这时候需要使用对应的含有debug 的版本进行override替换,方可调试。"})}),"\n",(0,n.jsxs)(e.h2,{id:"使用-rspack-debugcore",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#使用-rspack-debugcore",children:"#"}),"使用 ",(0,n.jsx)(e.code,{children:"@rspack-debug/core"})]}),"\n",(0,n.jsxs)(e.p,{children:["集成 Rspack 的框架或工具通常依赖 release 版本的 ",(0,n.jsx)(e.code,{children:"@rspack/core"}),"。release 包适合正常构建,但不包含部分仅用于调试的能力。当你需要在本地排查问题时,可以在实际执行构建的项目中通过 package manager override 将 ",(0,n.jsx)(e.code,{children:"@rspack/core"})," 替换为 ",(0,n.jsx)(e.code,{children:"@rspack-debug/core"}),"。"]}),"\n",(0,n.jsx)(e.p,{children:"以 pnpm 为例:"}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",title:"package.json",lang:"json",children:(0,n.jsxs)(e.code,{children:[(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"{"})}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:'  "pnpm"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:'    "overrides"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:'      "@rspack/core"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:' "npm:@rspack-debug/core@latest"'})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"    }"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"}
1,children:'    "peerDependencyRules"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:'      "allowAny"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" ["}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@rspack/*"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"]"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"    }"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"  }"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"}"})})]})})}),"\n",(0,n.jsx)(e.p,{children:"然后重新安装依赖,并继续运行原来的构建命令。例如项目通过 Rsbuild 构建时:"}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"bash",children:(0,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"pnpm"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" install"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:"RSPACK_PROFILE"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:"OVERVIEW"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-foreground)"},children:" RSPACK_TRACE_LAYER"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:"perfetto"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:" rsbuild"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" build"})]})]})})}),"\n",(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"@rspack-debug/core"})," 仅建议用于本地调试和问题诊断。如果正在排查特定版本的问题,建议将它固定到与原 ",(0,n.jsx)(e.code,{children:"@rspack/core"})," 相同的版本;排查结束后应移除 override。"]}),"\n",(0,n.jsxs)(e.h3,{id:"常见调试场景指南",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#常见调试场景指南",children:"#"}),"常见调试场景指南"]}),"\n",(0,n.jsxs)(e.h4,{id:"调试-rust",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#调试-rust",children:"#"}),"调试 Rust"]}),"\n",(0,n.jsxs)(e.p,{children:["只需在指定的 Rust 代码处设置断点后启动 ",(0,n.jsx)(e.code,{children:"Debug Rspack"})," 即可进行调试。"]}),"\n",(0,n.jsxs)(e.h4,{id:"调试-javascript",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#调试-javascript",children:"#"}),"调试 JavaScript"]}),"\n",(0,n.jsxs)(e.p,{children:["启动 ",(0,n.jsx)(e.code,{children:"Debug Rspack"})," 时,选择 ",(0,n.jsx)(e.code,{children:"--inspect"})," 或 ",(0,n.jsx)(e.code,{children:"--inspect-brk"})," 选项,然后启动 ",(0,n.jsx)(e.code,{children:"Attach JavaScript"})," 并选择相应进程的 PID 即可。"]}),"\n",(0,n.jsxs)(e.h4,{id:"调试已启动的-rspack-进程",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#调试已启动的-rspack-进程",children:"#"}),"调试已启动的 Rspack 进程"]}),"\n",(0,n.jsxs)(e.p,{children:["当 Rspack 被集成到其他框架或工具(如 Nx)中时,可能难以独立使用 Launch 模式启动 Rspack。此时,可以通过 attach 模式调试代码。启动 ",(0,n.jsx)(e.code,{children:"Attach Rust"})," 并选择 Rspack 所属进程的 PID 即可,启动 ",(0,n.jsx)(e.code,{children:"Attach JavaScript"})," 即可调试 JavaScript。"]}),"\n",(0,n.jsxs)(e.h4,{id:"调试发生死锁的-rspack-进程",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#调试发生死锁的-rspack-进程",children:"#"}),"调试发生死锁的 Rspack 进程"]}),"\n",(0,n.jsxs)(e.p,{children:["当使用 ",(0,n.jsx)(e.code,{children:"Attach Rust"})," 将调试器 attach 到 Rspack 所属进程后,点击 Debugger 的 Pause 按钮即可在死锁现场设置断点。"]}),"\n",(0,n.jsxs)(e.h2,{id:"rust-lldb",children:[(0,n.jsx)(e.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#rust-lldb",children:"#"}),"rust-lldb"]}),"\n",(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"rust-lldb"})," 可用于从 debug 版本中获取 panic 信息"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"bash",children:(0,n.jsx)(e.code,{children:(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"rust-lldb"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" --"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" node"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" /path/to/rspack"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" build"})]})})})}),"\n",(0,n.jsxs)(e.p,{children:["启动后,按住 ",(0,n.jsx)(e.code,{children:"r"})," 来执行程序。"]}),"\n",(0,n.jsxs)(e.p,{children:["例如,",(0,n.jsx)(e.code,{children:"examples/arco-pro"})," 运行崩溃了并且没有任何信息在",(0,n.jsx)(e.a,{href:"https://github.com/web-infra-dev/rspack/pull/3195/files",rel:"noopener noreferrer",target:"_blank",children:"这个修复"})," 之前:"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"txt",children:(0,n.jsxs)(e.code,{children:[(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"rspack/examples/arco-pro ❯ node ../../packages/rspack-cli/bin/rspack build"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"Rspack ██████████████████████░░░░░░░░░░░░░░░░░░ 56% building ./pages/welcome"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"zsh: bus error  node ../../packages/rspack-cli/bin/rspack build"})})]})})}),"\n",(0,n.jsxs)(e.p,{children:["使用 ",(0,n.jsx)(e.code,{children:"rust-lldb"})]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"bash",children:(0,n.jsx)(e.code,{children:(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"rspack/examples/arco-pro"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" ❯"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" rust-lldb"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" --"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" node"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" ../../packages/rspack-cli/bin/rspack"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string)"},children:" build"})]})})})}),"\n",(0,n.jsxs)(e.p,{children:["按下 ",(0,n.jsx)(e.code,{children:"r"})," 然后会打印:"]}),"\n",(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(e.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"txt",children:(0,n.jsxs)(e.code,{children:[(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"Process 23110 stopped"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"* thread #10, name = 'tokio-runtime-worker', stop reason = EXC_BAD_ACCESS (code=2, address=0x70000cc66560)"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"    frame #0: 0x0000000140d0db4b rspack.darwin-x64.node`swc_ecma_parser::parser::expr::ops::_$LT$impl$u20$swc_ecma_parser..parser..Parser$LT$I$GT$$GT$::parse_unary_expr::h29f49330a806839c(self=0x0000000000000000) at ops.rs:244"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"   241 	    /// Parse unary expression and update expression."})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"   242 	    ///"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"   243 	    /// spec: 'UnaryExpression'"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"-> 244 	    pub(in crate::parser) fn parse_unary_expr(&mut self) -> PResult<Box<Expr>> {"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"   245 	        trace_cur!(self, parse_unary_expr);"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"   246 	        let start = cur_pos!(self);"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"   247"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{children:"Target 0: (node) stopped."})})]})})})]})}function l(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:e}={...(0,a.R)(),...s.components};return e?(0,n.jsx)(e,{...s,children:(0,n.jsx)(c,{...s})}):c(s)}l.__RSPRESS_PAGE_META={},l.__RSPRESS_PAGE_META["zh%2Fcontribute%2Fdevelopment%2Fdebugging.mdx"]={toc:[{id:"通过-vs-code
1-调试",text:"通过 VS Code 调试",depth:2},{id:"使用-rspack-debugcore",text:"使用 `@rspack-debug/core`",depth:2},{id:"常见调试场景指南",text:"常见调试场景指南",depth:3},{id:"调试-rust",text:"调试 Rust",depth:4},{id:"调试-javascript",text:"调试 JavaScript",depth:4},{id:"调试已启动的-rspack-进程",text:"调试已启动的 Rspack 进程",depth:4},{id:"调试发生死锁的-rspack-进程",text:"调试发生死锁的 Rspack 进程",depth:4},{id:"rust-lldb",text:"rust-lldb",depth:2}],title:"Debugging",headingTitle:"Debugging",frontmatter:{description:"其他工具集成的一般是 Rspack 的 release 版本,其中并不包含调试信息,这时候需要使用对应的含有debug 的版本进行override替换,方可调试。"}},r.d(e,{default:()=>l})}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.