Skip to content

Commit 66c7e6c

Browse files
mdesmetclaude
andcommitted
fix: use __require fallback for __dirname to support Node < 20.11.0
`import.meta.dirname` is unavailable before Node 20.11.0. The previous fallback was dropped because `path`/`fileURLToPath` weren't in scope at that point in the bun-generated __commonJS IIFE. Using `__require` (a module-level closure bun always emits) works at any Node version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f90f52a commit 66c7e6c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

packages/dbt-tools/script/copy-python.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const pattern = /var __dirname\s*=\s*"[^"]*python-bridge[^"]*"/
2424
if (pattern.test(code)) {
2525
// import.meta.dirname is supported by Bun and Node >= 20.11.0.
2626
// Node 18 is EOL (April 2025), so no fallback needed.
27-
const replacement = `var __dirname = import.meta.dirname`
27+
const replacement = `var __dirname = typeof import.meta.dirname === "string" ? import.meta.dirname : __require("path").dirname(__require("url").fileURLToPath(import.meta.url))`
2828
code = code.replace(pattern, replacement)
2929
writeFileSync(indexPath, code)
3030
console.log(`Patched __dirname in dist/index.js`)

0 commit comments

Comments
 (0)