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)
Links to this issue
Commits related to this issue
- SVG import not working. https://github.com/parcel-bundler/parcel/issues/4145 — committed to cubing/cubing.js by lgarron 4 years ago
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
)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.Same issue
parcel watch
works fine,parcel build
fails.'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 thebundle-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:
Also bumping this as an issue I am experiencing. Seems to be when main is unset in package.json?
EDIT: Latest nightly is working
Sure: https://gist.github.com/cifkao/badeda38164e362a147b571053920520
parcel serve index.html
works fine (the CSS file contents get printed onto the console), butparcel 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 todist/navbar.js
. I was getting the hashReferences error.I had in my
package.json
:When I remove the
main:
property from mypackage.json
, the error goes away and my bundle works correctly (without --no-cache and --no-scope-hoist). Same error when usingmodule:
Hopefully this information might be of use.