Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to import @segment/analytics-next, Got unexpected undefined #9044

Open
louisgv opened this issue May 26, 2023 · 5 comments
Open

Failed to import @segment/analytics-next, Got unexpected undefined #9044

louisgv opened this issue May 26, 2023 · 5 comments

Comments

@louisgv
Copy link
Contributor

louisgv commented May 26, 2023

🐛 bug report

When importing @segment/analytics-next, parcel bundler throws an error.

🎛 Configuration (.babelrc, package.json, cli command)

{
  "your": { "config": "here" }
}

🤔 Expected Behavior

It should resolve the dependency correctly like the Set implementation but faster.

😯 Current Behavior

The new bundler using BitSet has a bug filtering out reusable dependency. Particularly the stack trace pointed me to this code:

https://github.com/parcel-bundler/parcel/blob/v2/packages/bundlers/default/src/DefaultBundler.js#L926-L943

After some debugging, it shows that the reachableRoots contains extra edge compared to the previous plain Set version. In particular with segment, it included an extra js assets that's actually not reachable, causing that else statement to throw at line 933.

💁 Possible Solution

Reverting back to the Set implementation worked. I think there might be a bug with the BitSet implementation.

🔦 Context

💻 Code Sample

import { AnalyticsBrowser } from "@segment/analytics-next"

🌍 Your Environment

Software Version(s)
Parcel 2.9.0
Node 18.x
npm/Yarn latest
Operating System Mac/Windows
@mischnic
Copy link
Member

Can you provide a complete reproduction? Just

import { AnalyticsBrowser } from "@segment/analytics-next";
console.log(AnalyticsBrowser);

builds fine for me

@louisgv
Copy link
Contributor Author

louisgv commented May 27, 2023

Here's the full stack trace:

(base) ➜  bug-parcel-segment git:(main) pnpm dev

> bug-parcel-segment@1.0.0 dev /Users/lab/Projects/test/bug-parcel-segment
> parcel manifest.json

Server running at http://localhost:1234
🚨 Build failed.

Error: Expected content key 9fed17cb32810a67 to exist

  Error: Expected content key 9fed17cb32810a67 to exist
      at nullthrows (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/nullthrows@1.1.1/node_modules/nullthrows/nullthrows.js:7:15)
      at AssetGraph.getNodeIdByContentKey (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+graph@2.9.0/node_modules/@parcel/graph/lib/ContentGraph.js:67:38)
      at /Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/SymbolPropagation.js:52:82
      at Array.map (<anonymous>)
      at propagateSymbols (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/SymbolPropagation.js:52:61)
      at AssetGraphBuilder.build (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/requests/AssetGraphRequest.js:168:62)
      at async Object.run (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/requests/AssetGraphRequest.js:60:37)
      at async RequestTracker.runRequest (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/RequestTracker.js:633:20)
      at async Object.run (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/requests/BundleGraphRequest.js:103:11)
      at async RequestTracker.runRequest (/Users/lab/Projects/test/bug-parcel-segment/node_modules/.pnpm/@parcel+core@2.9.0/node_modules/@parcel/core/lib/RequestTracker.js:633:20)

And reproduction:

https://github.com/louisgv/bug-parcel-segment

mb I should have mentioned the usage of web-extension config!

@mischnic
Copy link
Member

Reverting back to the Set implementation worked. I think there might be a bug with the BitSet implementation.

This sounds like it was working before upgrading for you, but I get the same error with 2.8.3? So I don't think it's related to the bitset?

@louisgv
Copy link
Contributor Author

louisgv commented May 28, 2023

This sounds like it was working before upgrading for you, but I get the same error with 2.8.3? So I don't think it's related to the bitset?

Interesting, I do have a custom resolver that lookup tsconfig's path for my project.

When using 2.8.3 I tested swapping out the BitSet implementation vs the Set implementation and the Set works while the BitSet didn't work. The only place I found in the debugger that shows a diff in the heap was the reusable set - namely it included an extra item when importing segment's package with their weird middleware thingy...

I traced upward a bit more to figure out what's adding stuff to that set, and the only place would be here:

https://github.com/parcel-bundler/parcel/blob/v2/packages/bundlers/default/src/DefaultBundler.js#L884-L886

But reverting it doesn't do anything xD.....

Maybe the ContentGraph edge lookup might be incompatible with BitSet somehow?.... :d

@github-actions github-actions bot added the Stale Inactive issues label Nov 25, 2023
@parcel-bundler parcel-bundler deleted a comment from github-actions bot Nov 25, 2023
@mischnic mischnic removed the Stale Inactive issues label Nov 25, 2023
@mischnic
Copy link
Member

mischnic commented Nov 25, 2023

I don't really know how to test if the output works, but Parcel builds successfully after upgrading to

    "@parcel/config-default": "2.10.3",
    "@parcel/config-webextension": "2.10.3",
    "parcel": "2.10.3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants