Skip to content

Commit b23d6d5

Browse files
committed
fix(app): convert bin/treq from CommonJS to ESM
The extensionless bin/treq file was using require() and __filename, but package.json declares "type": "module", causing Node.js to treat it as ESM where require is not defined.
1 parent 55ad3da commit b23d6d5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.changeset/fix-esm-bin-wrapper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@t-req/app": patch
3+
---
4+
5+
Fix bin/treq crash with "require is not defined in ES module scope" by converting to ESM imports

packages/app/bin/treq

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env node
22

3-
const childProcess = require("child_process")
4-
const fs = require("fs")
5-
const path = require("path")
6-
const os = require("os")
3+
import childProcess from "node:child_process"
4+
import fs from "node:fs"
5+
import path from "node:path"
6+
import os from "node:os"
7+
import { fileURLToPath } from "node:url"
78

89
function run(target) {
910
const result = childProcess.spawnSync(target, process.argv.slice(2), {
@@ -16,7 +17,7 @@ function run(target) {
1617
process.exit(result.status ?? 0)
1718
}
1819

19-
const scriptDir = path.dirname(fs.realpathSync(__filename))
20+
const scriptDir = path.dirname(fs.realpathSync(fileURLToPath(import.meta.url)))
2021

2122
const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" }
2223
const archMap = { x64: "x64", arm64: "arm64" }

0 commit comments

Comments
 (0)