Parcel: Error: Cannot read property 'hashReferences' of undefined

Created on 16 Feb 2020  ·  27Comments  ·  Source: parcel-bundler/parcel

🐛 bug report

When adding a synchronous dependency I get the following error:

 🚨 Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (/builds/kevincox/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:455:47)
    at getBundlesIncludedInHash (/builds/kevincox/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:459:24)
    at getBundlesIncludedInHash (/builds/kevincox/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:459:24)
    at assignComplexNameHashes (/builds/kevincox/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:447:27)
    at PackagerRunner.writeBundles (/builds/kevincox/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:101:5)
    at process._tickCallback (internal/process/next_tick.js:68:7)

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

All the state can be see in https://gitlab.com/kevincox/playerone/-/merge_requests/1.

In that PR I attempt to remove the workaround (using async imports) and you can see that it fails to build.

🤔 Expected Behavior

The build should work as intended.

💁 Possible Solution

This may be related to the fact that this library is imported from two places. The current graph looks like this (when experiencing the bug).

  • main.js

    • sync ga.js

    • async options.js

  • options.js

    • sync ga.js

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-nightly.113
| Node | v13.8.0
| npm | 6.13.6
| Operating System | Linux

Bug Confirmed Bug ✨ Parcel 2

Most helpful comment

I think I'm getting this error when my package.json has an invalid "main" field. Though I'm not sure what parcel considers valid. I'm just pointing my main at "main": "dist/index.html" which doesn't work while "main": "index.html" which unfortunately overwrites my real main file does complete a build.

× Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:490:47)
    at getBundlesIncludedInHash (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:494:7)
    at getBundlesIncludedInHash (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:494:7)
    at assignComplexNameHashes (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:482:31)
    at PackagerRunner.writeBundles (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:110:5)
    at async Parcel.build (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\Parcel.js:375:7)
    at async Parcel.run (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\Parcel.js:250:18)
    at async Command.run (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\parcel\lib\cli.js:155:7)

All 27 comments

Could you try again with the latest parcel@nightly release? The hashing system was recently overhauled.

Same issue.

% npx parcel --version
2.0.0-nightly.113
% npx parcel build --no-cache -- src/index.pug
🚨 Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:455:47)
    at getBundlesIncludedInHash (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:459:7)
    at getBundlesIncludedInHash (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:459:7)
    at assignComplexNameHashes (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:447:31)
    at PackagerRunner.writeBundles (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/PackagerRunner.js:101:5)
    at async Parcel.build (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/Parcel.js:376:7)
    at async Parcel.run (/home/kevincox/p/playerone/node_modules/@parcel/core/lib/Parcel.js:253:18)
    at async Command.run (/home/kevincox/p/playerone/node_modules/parcel/lib/cli.js:190:7)

This error happens practically if not every time you change a configuration property from the package.json or elsewhere.
To fix it most of the time just deleting the cache folder seems to fix it for me.
Not sure why it's doing that for you because you have the --no-cache flag.

To be honest I've been in the habit of removing the cache after every build as it seems to cause a lot of issues. So cache definitely isn't the problem here.

Thanks for having an easily reproducible example @kevincox! I've opened a PR that I believe should solve this issue. Temporarily, it looks like building with --no-scope-hoist resolves the issue until a fix is merged.

@Banou26 I think what you are referring to may be fixed by #4189, so keep an eye out on that one.

I think I'm getting this error when my package.json has an invalid "main" field. Though I'm not sure what parcel considers valid. I'm just pointing my main at "main": "dist/index.html" which doesn't work while "main": "index.html" which unfortunately overwrites my real main file does complete a build.

× Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:490:47)
    at getBundlesIncludedInHash (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:494:7)
    at getBundlesIncludedInHash (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:494:7)
    at assignComplexNameHashes (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:482:31)
    at PackagerRunner.writeBundles (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\PackagerRunner.js:110:5)
    at async Parcel.build (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\Parcel.js:375:7)
    at async Parcel.run (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\@parcel\core\lib\Parcel.js:250:18)
    at async Command.run (C:\Users\yuv\Downloads\gfloyd-backup\gh-website\node_modules\parcel\lib\cli.js:155:7)

I was getting this error on parcel@next (2.0.0-beta.1) using the --dist-dir flag on something like parcel build ./src/index.html --dist-dir=build, but not on parcel@nightly (2.0.0-nightly.322)

Can someone else confirm that this is fixed?

I'm receiving the error when when two builds in a monorepo share the default cache location -- in this case the cache dir is at the root of the repository.

If add --cache-dir=./.parcel-cache to the builds, I can work around the issue.

Can someone else confirm that this is fixed?

In the beta I have the same problem. In the version 2.0.0-nightly.358 it works fine.

I'm on 2.0.0-beta.1 and just encountered the issue in my bitbucket pipeline build

I have a similar structure as @ross-pfahler (monorepo with two packages build built by parcel at the same time)

Haven't tried 2.0.0-nigthly.3658 though

I'm getting this error with 2.0.0-nightly.366. EDIT: --no-scope-hoist solves the problem for me.

In my case it happens when I try to import a file using a named pipeline, e.g. import css from 'bundle-text:./style.css', and only when I try to build a JS target. When referencing the JS file from HTML, the error does not occur.

It would be great to at least display a more informative error message (showing which bundle is referenced that is not found).

In my case it happens when I try to import a file using a named pipeline, e.g. import css from 'bundle-text:./style.css', and only when I try to build a JS target. When referencing the JS file from HTML, the error does not occur.

Can you reproduce this consistently? Could you provide a full code sample?

It would be great to at least display a more informative error message (showing which bundle is referenced that is not found).

We should rather fix the bug itself....

Can you reproduce this consistently? Could you provide a full code sample?

Sure: https://gist.github.com/cifkao/badeda38164e362a147b571053920520

parcel serve index.html works fine (the CSS file contents get printed onto the console), but parcel build index.js fails with this error.

At least in @cifkao's example, this is caused by inline bundles not being processed (as they shouldn't)
https://github.com/parcel-bundler/parcel/blob/64ebc3757a7c36432d55ee4d791e96e30dab242f/packages/core/core/src/PackagerRunner.js#L116
so bundleInfoMap[someInlineBundle.id] is undefiend.
But they are still listed in the hashReferences of their parent bundles: https://github.com/parcel-bundler/parcel/blob/64ebc3757a7c36432d55ee4d791e96e30dab242f/packages/core/core/src/PackagerRunner.js#L658
and then bundleInfoMap[someInlineBundle.id].hashReferences fails. I'm not quite sure if they should just be skipped or handled in some other way.

I also get this error now too, but with JS instead of CSS.

What seems to have triggered it for me is using ES6 static imports from inside an ES6 dynamic import which I had also imported in the document itself.

The following minimal example reproduces:

{edit} as a gist: https://gist.github.com/dgkimpton/278657a777eb898075b9551ff38606c2

package.json

{
 "name": "parcel-test",
 "version": "1.0.0",
 "scripts": {
  "assemble": "parcel build index.html"
 },
 "devDependencies": {
  "parcel": "^2.0.0-nightly.372"
 }
}

index.html

<!DOCTYPE html>
<html>
<body>
    <script type="module">
        import { something } from './othermodule.mjs';
        document.addEventListener('load', () => {
            something();
            import('./module.mjs').then((m) => m.doStuff());
        });
    </script>
</body>
</html>

module.mjs

import { something } from './othermodule.mjs';

export function doStuff() {
    something();
}

othermodule.mjs

export function something() {
    console.warn('hmmm');
}

|Software | Version(s)|
|-- | --|
|Parcel | [email protected]|
|Node | v14.4.0|
|npm |6.14.5|
|Operating System | Windows 10/git bash|

npm run assemble

� Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:529:47)
    at getBundlesIncludedInHash (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:533:7)
    at getBundlesIncludedInHash (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:533:7)
    at assignComplexNameHashes (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:521:31)
    at PackagerRunner.writeBundles (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:112:5)
    at async Parcel.build (E:\code\web\parcel-error\node_modules\@parcel\core\lib\Parcel.js:398:7)
    at async Parcel.run (E:\code\web\parcel-error\node_modules\@parcel\core\lib\Parcel.js:273:18)
    at async Command.run (E:\code\web\parcel-error\node_modules\parcel\lib\cli.js:234:7)

I also get this error now too, but with JS instead of CSS.

What seems to have triggered it for me is using ES6 static imports from inside an ES6 dynamic import which I had _also_ imported in the document itself.

The following minimal example reproduces:

{edit} as a gist: https://gist.github.com/dgkimpton/278657a777eb898075b9551ff38606c2

package.json

{
 "name": "parcel-test",
 "version": "1.0.0",
 "scripts": {
  "assemble": "parcel build index.html"
 },
 "devDependencies": {
  "parcel": "^2.0.0-nightly.372"
 }
}

index.html

<!DOCTYPE html>
<html>
<body>
  <script type="module">
      import { something } from './othermodule.mjs';
      document.addEventListener('load', () => {
          something();
          import('./module.mjs').then((m) => m.doStuff());
      });
  </script>
</body>
</html>

module.mjs

import { something } from './othermodule.mjs';

export function doStuff() {
  something();
}

othermodule.mjs

export function something() {
  console.warn('hmmm');
}

Software Version(s)
Parcel [email protected]
Node v14.4.0
npm 6.14.5
Operating System Windows 10/git bash

npm run assemble

� Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:529:47)
    at getBundlesIncludedInHash (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:533:7)
    at getBundlesIncludedInHash (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:533:7)
    at assignComplexNameHashes (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:521:31)
    at PackagerRunner.writeBundles (E:\code\web\parcel-error\node_modules\@parcel\core\lib\PackagerRunner.js:112:5)
    at async Parcel.build (E:\code\web\parcel-error\node_modules\@parcel\core\lib\Parcel.js:398:7)
    at async Parcel.run (E:\code\web\parcel-error\node_modules\@parcel\core\lib\Parcel.js:273:18)
    at async Command.run (E:\code\web\parcel-error\node_modules\parcel\lib\cli.js:234:7)

Yep this my problem too, i think we can't use ES6 Export/Import in Parcel. Feels Bad. Do you have any solution for this stuff?

Also bumping this as an issue I am experiencing. Seems to be when main is unset in package.json?

EDIT: Latest nightly is working

I got this issue as well with a recent nightly (2.0.0-nightly.428).

parcel build src/index.html --dist-dir ./dist --public-url=$PUBLIC_PATH --cache-dir ./.parcel-cache --detailed-report
🚨 Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (/Users/ibaratz/GitHub2/unified-shell/node_modules/@parcel/core/lib/PackagerRunner.js:671:47)
    at getBundlesIncludedInHash (/Users/ibaratz/GitHub2/unified-shell/node_modules/@parcel/core/lib/PackagerRunner.js:675:7)
    at assignComplexNameHashes (/Users/ibaratz/GitHub2/unified-shell/node_modules/@parcel/core/lib/PackagerRunner.js:663:31)
    at PackagerRunner.writeBundles (/Users/ibaratz/GitHub2/unified-shell/node_modules/@parcel/core/lib/PackagerRunner.js:224:5)
    at async Parcel.build (/Users/ibaratz/GitHub2/unified-shell/node_modules/@parcel/core/lib/Parcel.js:584:7)
    at async Parcel.run (/Users/ibaratz/GitHub2/unified-shell/node_modules/@parcel/core/lib/Parcel.js:459:18)
    at async Command.run (/Users/ibaratz/GitHub2/unified-shell/node_modules/parcel/lib/cli.js:352:7)

cc @ross-pfahler

@ittaibaratz Are you using import foo from 'bundle-text:./something'; or import foo from 'data-url:./something'; (like here)? Or inline script tags with imports? Just trying to verify that there are not even more situations where this occurs...

@ittaibaratz Are you using import foo from 'bundle-text:./something'; or import foo from 'data-url:./something'; (like here)? Or inline script tags with imports? Just trying to verify that there are not even more situations where this occurs...

We have import SomeSVG from 'url:path/to/image.svg';

Note the issue is very intermittent, and clearing the cache folder and re-running the build gets rid of it.

I have exact same error with lates nightly build (2.0.0-nightly.443)

$ parcel build src/index.html --dist-dir=public/dist --public-url=/dist/ --log-level=verbose
🚨 Build failed.
Error: Cannot read property 'hashReferences' of undefined
TypeError: Cannot read property 'hashReferences' of undefined
    at getBundlesIncludedInHash (/Volumes/Work/testomato.com/node_modules/@parcel/core/lib/PackagerRunner.js:671:47)
    at getBundlesIncludedInHash (/Volumes/Work/testomato.com/node_modules/@parcel/core/lib/PackagerRunner.js:675:7)
    at assignComplexNameHashes (/Volumes/Work/testomato.com/node_modules/@parcel/core/lib/PackagerRunner.js:663:31)
    at PackagerRunner.writeBundles (/Volumes/Work/testomato.com/node_modules/@parcel/core/lib/PackagerRunner.js:224:5)
    at async Parcel._build (/Volumes/Work/testomato.com/node_modules/@parcel/core/lib/Parcel.js:617:7)
    at async Parcel.run (/Volumes/Work/testomato.com/node_modules/@parcel/core/lib/Parcel.js:487:18)
    at async Command.run (/Volumes/Work/testomato.com/node_modules/parcel/lib/cli.js:361:7)

solved with --no-scope-hoist param build works well.

hey @mischnic -- in case you want another example, here is an easy repro of a similar problem: https://github.com/ross-pfahler/parcel-2-demos/pull/5. Steps are in PR body.

I personally get this bug every time I recompile the stylesheets (PostCSS + SugarSS). Clearing the cache after every change has been the only thing that works, but this isn't ideal.

Also seeing this specifically with PostCSS + SugarSS

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Niggler picture Niggler  ·  3Comments

jsftw86 picture jsftw86  ·  3Comments

dotdash picture dotdash  ·  3Comments

oliger picture oliger  ·  3Comments

medhatdawoud picture medhatdawoud  ·  3Comments