bun
bun copied to clipboard
Use of lodash raises runtime error
Version
0.1.5
Platform
Darwin Andys-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64 x86_64
What steps will reproduce the bug?
- Create a new bun project
-
bun add lodash
- Edit
src/index.js
with
// import { uniqWith, isEqual } from 'lodash';
import pkg from 'lodash';
const { uniqWith, isEqual } = pkg;
console.log('Hello, World!');
const a1 = [1,2,3]
const a2 = [1,2,3]
console.log(isEqual(a1, a2))
- run
bun src/index.js
How often does it reproduce? Is there a required condition?
Each time.
What is the expected behavior?
Hello, World!
true
What do you see instead?
bun src/index.js
Hello, World!
3341 |
3342 | var objIsObj = objTag == objectTag,
3343 | othIsObj = othTag == objectTag,
3344 | isSameTag = objTag == othTag;
3345 |
3346 | if (isSameTag && isBuffer(object)) {
^
TypeError: Cannot convert undefined or null to object
at baseIsEqualDeep (/Users/andy/Devel/test-bun/bun03-again/node_modules/lodash/lodash.js:3346:23)
at /Users/andy/Devel/test-bun/bun03-again/src/index.js:9:12
Additional information
Running using node
works OK. E.g. node src/index.js
Hello, World!
true
where package.json
is
{
"name": "bun03-again",
"type": "module",
"version": "0.0.3",
"module": "src/index.js",
"devDependencies": {
"bun-types": "latest"
},
"dependencies": {
"lodash": "^4.17.21"
}
}
Test case can be simplified. Caused (somehow) by Lodash caching the native Buffer.isBuffer
as a JS variable.
console.log(Buffer.isBuffer(myVariable)); // works fine
let func = Buffer.isBuffer;
console.log(func(myVariable)); // TypeError: Cannot convert undefined or null to object
I don't know if it helps, but upgrade bun.
Solved in #1076. Close for now. Could you please give it another try when v0.1.9 comes out?