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

Parcel 2 does not include dependencies correctly in split bundles and Web Workers with scope hoisting disabled #5864

Closed
cfoust opened this issue Feb 17, 2021 · 1 comment · Fixed by #6582

Comments

@cfoust
Copy link

cfoust commented Feb 17, 2021

🐛 bug report

Using the latest versions of Parcel 2, dependencies are incorrectly excluded from code split bundles and Worker bundles that are descendants of that code split when scope hoisting is disabled. This triggers a Cannot find module '[id]' on page load on sites built with the parcel build command.

Scope hoisting is still really buggy for us and we haven't been able to debug that, so it's disabled. I'll likely submit a separate issue for that.

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

Take a look at this repository: https://github.com/embarktrucks/parcel-split-webworker-issue

🤔 Expected Behavior

Parcel should include pertinent dependencies in split bundles and Worker bundles that descend from those.

😯 Current Behavior

A bunch of dependencies are excluded.

To try this out, copy this repository into your parcel/ repository at packages/examples/, cd into the directory, and run:

yarn run parcel build --no-scope-hoist --no-cache index.html

You will get output similar to this:

dist/browser/index.fe0b0221.js                            70.25 KB    2.57s                     
├── ../../../node_modules/lodash/lodash.js                69.08 KB    417ms                     
└── Code from unknown sourcefiles                          1.17 KB      0ms                     

dist/browser/index.85b8c16e.js                              3.8 KB    974ms                     
├── Code from unknown sourcefiles                          1.29 KB      0ms                     
├── ../../runtimes/js/src/JSRuntime.js                       625 B     22ms                     
├── ../../runtimes/js/src/relative-path.js                   478 B     49ms                     
├── ../../runtimes/js/src/bundle-url.js                      447 B     50ms                     
├── ../../runtimes/js/src/loaders/browser/js-loader.js       407 B     45ms                     
├── ../../runtimes/js/src/cacheLoader.js                     282 B      9ms                     
├── ../../runtimes/js/src/bundle-manifest.js                 246 B     39ms                     
└── src/index.js                                              85 B    1.95s                     

dist/browser/split.0112a5d5.js                             1.61 KB    973ms                     
├── Code from unknown sourcefiles                          1.14 KB      0ms                     
├── ../../runtimes/js/src/get-worker-url.js                  221 B     51ms                     
├── ../../runtimes/js/src/JSRuntime.js                       157 B     23ms                     
└── src/split.js                                             105 B     36ms                     
# ^^ LODASH NOT INCLUDED

dist/browser/worker.f5b2ae32.js                            1.38 KB    974ms                     
└── src/worker.js                                             19 B    378ms                     
# ^^ LODASH NOT INCLUDED

dist/browser/index.html                                      223 B    972ms                     
└── index.html                                               228 B    1.82s                     
Done in 8.79s.  

If you look in the worker.[hash].js and split.[hash].js files, they point
to lodash but don't actually include it, triggering an error Cannot find module on page load.

💁 Possible Solution

We fixed this by monkey-patching the DefaultBundler by commenting out these lines.

🔦 Context

We gate a ton of functionality behind splits + web workers because our web application is pretty complex. It appears that few users do this, so I imagine this is not covered by your tests.

💻 Code Sample

https://github.com/embarktrucks/parcel-split-webworker-issue

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.577 and current master commit
Node 15.4
Yarn 1.22.5
Operating System Ubuntu 16.04
@cfoust
Copy link
Author

cfoust commented Jul 13, 2021

Thank you!

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

Successfully merging a pull request may close this issue.

3 participants