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

🐛 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

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 14
  • Comments: 48 (20 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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.

Running into the same issue during parcel build. --no-content-hash fixes it.

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.

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.

If building for ESM there is no solution or workaround 😦 Meanwhile the issue got one year old 🎉

I just encountered this (on 2.0.0-nightly.573+31f431d9) and the --no-scope-hoist suggestion fixed it, although I am not clear what introduced it. I am importing svg’s, which is possibly related? 🤷

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.

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.

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)

Same issue parcel watch works fine, parcel build fails.

  • I’m using the web-extension config
  • I am using 'bundle-text:' import at one place

--no-content-hash helped.


[Jul 11, 2022] Update:

The above doesn’t really work. It makes the build command finish execution without errors, but the resulting build turns out to be broken. The issue is with the code surrounding the bundle-text: import. The other (normal) import in the file doesn’t seem to work and I get a runtime error:
Cannot find module ‘81IKK’ (The latter I guess is just a hashed name of a module from node_modules)

Another reproduction:

<script type="module">
  import * as b from "./b.js";
  console.log(b);
</script>
<script src="./a.js" type="module"></script>
// a.js
import * as b from "./b.js";
console.log(b);

// b.js
export const a = 1;

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

EDIT: Latest nightly is working

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.

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.

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

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.

I have a build where src/navbar.tsx is the entry point. This gets compiled to dist/navbar.js. I was getting the hashReferences error.

I had in my package.json:

{
  "main": "./dist/navbar.js",
}

When I remove the main: property from my package.json, the error goes away and my bundle works correctly (without --no-cache and --no-scope-hoist). Same error when using module: Hopefully this information might be of use.