bun
bun copied to clipboard
"assert is not a function" error when calling the `assert` module as a function
Version
0.1.5
Platform
Microsoft Windows NT 10.0.19044.0 x64
What steps will reproduce the bug?
import assert from 'assert'
assert(true)
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
the code above works in node because its assert
module can be called as a function, which is an alias to assert.ok
, as you can see from the typescript types:
// assert.d.ts
declare module 'assert' {
/** An alias of `assert.ok()`. */
function assert(value: any, message?: string | Error): asserts value;
namespace assert {
// ...
}
}
What do you see instead?
$ bun asdf.ts
1 | import assert from 'assert'
2 |
3 | assert(true)
^
TypeError: assert is not a function. (In 'assert(true)', 'assert' is an instance of Object)
Additional information
No response
I think this a problem with esbuild (https://esbuild.github.io) when compiling the node fallback for Assert (https://www.npmjs.com/package/assert). Investigating further...
Fixed in Bun v0.2.0
bun upgrade --canary