The problem
Tinypool.version throws ReferenceError: __dirname is not defined.
The package declares "type": "module", so Node loads dist/index.js as an ES module — and an ES module has no __dirname binding. The getter reads one.
Reproduce
probe.mjs:
import Tinypool from 'tinypool'
console.log(Tinypool.version)
$ node probe.mjs
ReferenceError: __dirname is not defined
I ran a control in the same file first — a bare __dirname reference, to confirm the scope really is an ES module rather than something my harness leaked:
control (bare __dirname here): ReferenceError
Tinypool.version THREW: ReferenceError: __dirname is not defined
Where
src/index.ts, in static get version():
static get version(): string {
const { version } = JSON.parse(
readFileSync(join(__dirname, '../package.json'), 'utf-8')
)
...
which lands in dist/index.js:759 in the published 2.1.2 tarball. package.json has "type": "module" and dist/index.js is the only entry, so there is no CommonJS path to this code.
There is no createRequire or fileURLToPath shim in the emitted file — I grepped it — so nothing supplies __dirname at runtime.
Why it has probably gone unnoticed
version is the only thing reaching it. Everything else in the public API works, so a consumer only hits this if they read that property.
Fix
The usual ESM equivalent, e.g.
import { fileURLToPath } from 'node:url'
const here = dirname(fileURLToPath(import.meta.url))
or reading the version at build time. Happy to open a PR if you'd like one.
Notes
Found by an automated checker I'm building that flags CommonJS bindings in files Node resolves as ES modules. I verified this one by hand against the published 2.1.2 tarball before filing, and checked the open and closed issues for an existing report.
The problem
Tinypool.versionthrowsReferenceError: __dirname is not defined.The package declares
"type": "module", so Node loadsdist/index.jsas an ES module — and an ES module has no__dirnamebinding. The getter reads one.Reproduce
probe.mjs:I ran a control in the same file first — a bare
__dirnamereference, to confirm the scope really is an ES module rather than something my harness leaked:Where
src/index.ts, instatic get version():which lands in
dist/index.js:759in the published 2.1.2 tarball.package.jsonhas"type": "module"anddist/index.jsis the only entry, so there is no CommonJS path to this code.There is no
createRequireorfileURLToPathshim in the emitted file — I grepped it — so nothing supplies__dirnameat runtime.Why it has probably gone unnoticed
versionis the only thing reaching it. Everything else in the public API works, so a consumer only hits this if they read that property.Fix
The usual ESM equivalent, e.g.
or reading the version at build time. Happy to open a PR if you'd like one.
Notes
Found by an automated checker I'm building that flags CommonJS bindings in files Node resolves as ES modules. I verified this one by hand against the published 2.1.2 tarball before filing, and checked the open and closed issues for an existing report.