oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.06k stars 2.76k forks source link

Error when use Bun build and @google-cloud libraries #9367

Open ftognetto opened 7 months ago

ftognetto commented 7 months ago

What version of Bun is running?

1.0.30+1424a196f

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

In my project I'm currently using @google-cloud/pubsub and @google-cloud/logging When I run the project with bun run index.ts I have no problem. When I build the project (bun build index.ts --target node (or bun, is the same) and run the index.js output I get

Error: undefined undefined: undefined
    at callErrorFromStatus (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:73779:19)
    at Object.onReceiveStatus (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:74458:68)
    at Object.onReceiveStatus (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:74292:139)
    at Object.onReceiveStatus (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:74259:174)
    at file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:77548:67
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:74429:30)
    at ServiceClientImpl.<anonymous> (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:74721:17)
    at file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:116309:23
    at file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:106773:14
    at repeat (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:106816:21)
    at Task._apiCall (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:106849:9)
    at Task.run (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:105558:33)
    at BundleExecutor._runNow (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:105750:12)
    at Timeout._onTimeout (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:105715:16)
    at listOnTimeout (node:internal/timers:573:17)
Emitted 'error' event on DerivedLogger instance at:
    at DerivedLogger.transportEvent (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:155313:14)
    at LoggingWinston.emit (node:events:526:35)
    at errorOrDestroy (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:26865:14)
    at onwriteError (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:28421:7)
    at onwrite (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:28439:7)
    at WritableState.onwrite (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:28306:7)
    at newCallback (file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:143776:13)
    at file:///Users/fabriziotognetto/quantosprojects/bigartwall/bigartwall-backend/bun/services/album-service/dist/index.js:64731:19 {
  code: undefined,
  details: undefined,
  metadata: Metadata { internalRepr: Map(0) {}, options: {} },
  note: 'Exception occurred in retry method that was not classified as transient'
}

Node.js v20.10.0

The same error when I try to send a message with @google-cloud/pubsub

What is the expected behavior?

Something I don't understand is happening during the transpiling done by Bun.build. I expect to make @google-cloud libraries work after Bun.build

What do you see instead?

No response

Additional information

I'm currently using bun workspace.

The tsconfig I'm using is (taken from bun best practices)

{
    "compilerOptions": {
        // Enable latest features
        "lib": ["ESNext"],
        "target": "ESNext",
        "module": "ESNext",
        "moduleDetection": "force",
        "jsx": "preserve", //"jsx": "react-jsx",
        "allowJs": true,

        // Bundler mode
        "moduleResolution": "Bundler",
        "allowImportingTsExtensions": true,
        "verbatimModuleSyntax": true,
        "noEmit": true,
        "esModuleInterop": true,

        "allowSyntheticDefaultImports": true,

        // Best practices
        "strict": true,
        "skipLibCheck": true,
        "noFallthroughCasesInSwitch": true,

        // Some stricter flags
        "noUnusedLocals": true,
        "noUnusedParameters": false,
        "noPropertyAccessFromIndexSignature": false,

        "types": [
            "bun-types" // add Bun global
        ]
    }
}
Electroid commented 7 months ago

Is it possible to share a minimal reproduction in code?

ftognetto commented 7 months ago

HI @Electroid yes ofc.

I create a repo here https://github.com/ftognetto/-oven-sh-bun-issues-9367

To use this repo you should have a gcp project with pubsub enabled. There are two env variables to setup

I created some scripts in package.json that already load those env so you have everything in one place

Notes:

ftognetto commented 7 months ago

Hi @Electroid forgive the insistence are there any update on this? We are currently waiting for migrating an old lerna monorepo to bun workspaces and we have scheduled work on it. If you need I can send you in private a service account so you can test the repo I sent without additional operation from your side. Let me know, thank you

github-actions[bot] commented 2 months ago

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.