bun icon indicating copy to clipboard operation
bun copied to clipboard

Use of lodash raises runtime error

Open abulka opened this issue 1 year ago • 2 comments

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?

  1. Create a new bun project
  2. bun add lodash
  3. 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))
  1. 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"
  }
}

abulka avatar Jul 31 '22 10:07 abulka

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

JL102 avatar Aug 06 '22 07:08 JL102

I don't know if it helps, but upgrade bun.

xHyroM avatar Aug 07 '22 05:08 xHyroM

Solved in #1076. Close for now. Could you please give it another try when v0.1.9 comes out?

zhuzilin avatar Aug 15 '22 07:08 zhuzilin