Parcel: Cannot read property 'depAssets' of undefined

Created on 19 Nov 2018  路  2Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

command: npx parcel build --experimental-scope-hoisting parcel/main.js

馃敠 Context

debug info _bundle_loader not found

[12:31:06]: 馃毃  Cannot read property 'depAssets' of undefined 
[12:31:06]:     at JSConcatPackager.resolveModule (<work_space>/node_modules/parcel-bundler/src/packagers/JSConcatPackager.js:551:19)
    at CallExpression (<work_space>/node_modules/parcel-bundler/src/scope-hoisting/concat.js:152:28)
    at NodePath._call (<work_space>/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (<work_space>/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (<work_space>/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (<work_space>/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (<work_space>/node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (<work_space>/node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (<work_space>/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (<work_space>/node_modules/@babel/traverse/lib/path/context.js:95:18)

馃捇 Code Sample

// main.js
const main = async () => {
    const x = await import("./a.js");

    console.log(x);
};
main();

// a.js
console.log('1');

const b = () => import('./b.js');   // b.js is an empty file.   It is precisely because of this problem. 
// import b from 'b.js' // If it's synchronized, it's okay.

export const y = 1;

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.10.3
| Node | 10
| npm/Yarn |
| Operating System |

Bug 馃尦 Tree Shaking

Most helpful comment

Tree shaking doesn't seem to work when dynamically imported bundles use dynamic imports themselves.

JSConcatPackage#resolveModule gets called with name: "./bundle-url".

All 2 comments

Tree shaking doesn't seem to work when dynamically imported bundles use dynamic imports themselves.

JSConcatPackage#resolveModule gets called with name: "./bundle-url".

Is there any progress on this issue? This is still an issue for the current master branch.

I tried to have a look but didn't found the root cause of it. All I found out is:

  • the ./bundle-url import comes from builtins/bundle-loader.js. Inlining the content of that file makes the build pass and also the execution works fine, but this does not look like a great solution to me.
  • It looks like the import is not added to the child bundles, maybe the dependencies for _bundle_loader are not collected anymore because its already in the main bundle? I could ensure that its correclty added for all assets from builtins/bundle-loader.js
  • when adding all dependencies from the entryAsset to the assets map in the packager/JSConcatPackager.js the build passes but it failes when executing the JavaScript with module not found errors: for (let [, mod] of this.bundle.entryAsset.depAssets) { this.assets.set(mod.id, mod); }

Maybe this is helpful to someone else how likes to have a look. Would love to see this fixed!

Was this page helpful?
0 / 5 - 0 ratings