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

Async import from both worker and child worker: 'Cannot find module' #5504

Closed
mischnic opened this issue Dec 19, 2020 · 2 comments · Fixed by #6582
Closed

Async import from both worker and child worker: 'Cannot find module' #5504

mischnic opened this issue Dec 19, 2020 · 2 comments · Fixed by #6582

Comments

@mischnic
Copy link
Member

🐛 bug report

Doing async imports in nested workers doesn't work beacuse ./loaders/worker/js-loader isn't available in the inner worker.

😯 Current Behavior

child-worker.b4a550ff.js:59 Uncaught Error: Cannot find module '2TfhN'
    at newRequire (child-worker.b4a550ff.js:59)
    at newRequire (child-worker.b4a550ff.js:43)
    at localRequire (child-worker.b4a550ff.js:81)
    at Object.1xm4F../loaders/worker/js-loader (child-worker.b4a550ff.js:144)
    at newRequire (child-worker.b4a550ff.js:69)
    at localRequire (child-worker.b4a550ff.js:81)
    at Object.39YhH../async.js (child-worker.b4a550ff.js:142)
    at newRequire (child-worker.b4a550ff.js:69)
    at child-worker.b4a550ff.js:118
    at child-worker.b4a550ff.js:141

💁 Possible Solution

This is probably because the context is actually the same between main and child worker, so Parcel thinks it can reuse the asset from a parent bundle?

💻 Code Sample

parcel build index.html --no-scope-hoist

<script src="index.js"></script>
// index.js
new Worker("./worker.js");

// worker.js
new Worker("./child-worker.js");
import("./async.js").then((v) => console.log("worker: async=", v));

// child-worker.js
import("./async.js").then((v) => console.log("child worker: async=", v));

// async.js
export const async = "async!";

🌍 Your Environment

Software Version(s)
Parcel f89e5ef
@mischnic
Copy link
Member Author

Another case that might be caused by the same problem:

Uncaught Error: Cannot find module 'WkjLV'
    at newRequire (ParcelWorker.3cce57a2.js:59)
    at newRequire (ParcelWorker.3cce57a2.js:43)
    at localRequire (ParcelWorker.3cce57a2.js:81)
    at Object.1iSde../bundle-manifest (ParcelWorker.3cce57a2.js:142)
    at newRequire (ParcelWorker.3cce57a2.js:69)
    at ParcelWorker.3cce57a2.js:118
    at ParcelWorker.3cce57a2.js:141
    at ParcelWorker.3848616d.js:1

parcel build index.html --no-scope-hoist

<script src="index.js"></script>
// index.js
new Worker("./ParcelWorker.js");

// ParcelWorker.js
import './Parcel';
import("./async.js").then((v) => console.log("worker: async=", v));

// async.js
console.log("async");
export const async = "async!";

// Parcel.js
import WorkerFarm from './Worker';

// Worker.js
import "./common.js";
if (Date.now() === 0) {
	new Worker("./child.js");
}

// common.js
(some large file to trigger this becoming a shared bundle: 20kb)

// child.js
import "./Parcel";

@lgarron
Copy link

lgarron commented Dec 23, 2020

I'm also able to trigger this with normal module imports:

https://github.com/lgarron/parcel-2-worker-common-import

The cubing package contains a lot of imports, but a search of cubing/dist/esm (which you can confirm is used by Parcel by deleting cubing/dist/cjs) shows that there are no async import calls.

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