bun icon indicating copy to clipboard operation
bun copied to clipboard

"assert is not a function" error when calling the `assert` module as a function

Open DetachHead opened this issue 2 years ago • 1 comments

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

DetachHead avatar Jul 31 '22 12:07 DetachHead

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...

JL102 avatar Aug 05 '22 22:08 JL102

Fixed in Bun v0.2.0

bun upgrade --canary

Jarred-Sumner avatar Oct 10 '22 20:10 Jarred-Sumner