parcel
parcel copied to clipboard
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 |
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';
orimport 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
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? 🤷
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;
If building for ESM there is no solution or workaround :( Meanwhile the issue got one year old 🎉
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.
I can't reproduce with @mischnic's case in the latest nightly anymore. @GrantAtStreamba what version of Parcel are you using and do you have any more details on what could reproduce it?
Going to close this since it seems to be working now. If you manage to reproduce it still, please let us know.
The original case is still present https://gitlab.com/kevincox/playerone/-/merge_requests/1. I have rebased the example against Parcel 2.0.0.
I have also found a new case on Parcel 2.0.0 that worked previously. https://gitlab.com/kevincox/playerone/-/merge_requests/65 which appears to be triggered by this import https://gitlab.com/kevincox/playerone/-/blob/72879318ae5db83cb3174871e50b281c297a5b95/src/a/options.ts#L1
Also experiencing this issue when trying to workaround https://github.com/parcel-bundler/parcel/issues/7609 by using bundle-text:
instead :(
🚨 Build failed.
Error: Cannot read properties of undefined (reading 'hashReferences')
TypeError: Cannot read properties of undefined (reading 'hashReferences')
at getBundlesIncludedInHash ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/requests/WriteBundlesRequest.js:147:47)
at getBundlesIncludedInHash ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/requests/WriteBundlesRequest.js:151:7)
at assignComplexNameHashes ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/requests/WriteBundlesRequest.js:140:105)
at Object.run ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/requests/WriteBundlesRequest.js:115:5)
at async RequestTracker.runRequest ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/RequestTracker.js:725:20)
at async Object.run ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/requests/ParcelBuildRequest.js:74:20)
at async RequestTracker.runRequest ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/RequestTracker.js:725:20)
at async Parcel._build ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/Parcel.js:397:11)
at async Parcel.run ([project_dir]/.yarn/cache/@parcel-core-npm-2.2.1-62c0c81716-f06b61c184.zip/node_modules/@parcel/core/lib/Parcel.js:276:18)
at async run ([project_dir]/.yarn/cache/parcel-npm-2.2.1-088c07d8bf-081fdc011a.zip/node_modules/parcel/lib/cli.js:374:7)
For me, falling back to fs.readFileSync
worked as an ugly workaround :)
Another confirmation for bundle-text:
causing the problem. It used to work for me in 2.3.2, but upon upgrading to 2.5.0 I'm hitting this issue
For me falling back on fs does not work, as I actually want Parcel to process imports in the CSS first =\
https://github.com/shoonia/parcel-transformer-css-to-string/issues/6 does not work for similar reasons =\
Ah interestingly - it only happens in watch
mode but not for build, with following configurations. will check what is causing the difference:
"build": "parcel build source/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --no-cache --detailed-report 0",
"watch": "parcel watch source/manifest.json --dist-dir distribution --no-cache --no-hmr",
so removing --no-hmr
seems to have resolved this for me 🤷♂️
But if I were to remove --no-content-hash
from the build command, I start hitting this issue in the build command 🙈
Running into the same issue during parcel build
. --no-content-hash
fixes it.
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)
Has anyone been able to circumvent the issue?
Because the --no-content-hash
solution, as stated by @everdimension , doesn't really work.
@everdimension @avalanche1 I think you may be hitting another bug - see #8071
@everdimension @avalanche1 I think you may be hitting another bug - see #8071
For reference, a workaround in the linked issue can be found in this comment. I've also outlines that solution below.
As mentioned in everdimension's comment, adding --no-content-hash
removes the build error but introduces a runtime error Cannot find module '#####'
. The solution is to specify --no-content-hash
and then also disable code splitting by adding the following to your package.json
file:
"@parcel/bundler-default": {
"minBundles": 10000000,
"minBundleSize": 3000,
"maxParallelRequests": 20
}
Keep in mind that this solution removes code-splitting so you will end up with larger individual files. If you're developing a web extension this is generally not an issue since the files are loaded locally anyways. However, Firefox does have a hard limit of 4MB per file ([1], [2]), which could prevent this solution from working on the Firefox Addons site.
@everdimension @avalanche1 I think you may be hitting another bug - see #8071
For reference, a workaround in the linked issue can be found in this comment. I've also outlined that solution below.
As mentioned in everdimension's comment, adding --no-content-hash
removes the build error but introduces a runtime error Cannot find module '#####'
. The solution is to specify --no-content-hash
and then also disable code splitting by adding the following to your package.json
file:
"@parcel/bundler-default": {
"minBundles": 10000000,
"minBundleSize": 3000,
"maxParallelRequests": 20
}
Keep in mind that this solution removes code-splitting so you will end up with larger individual files. If you're developing a web extension this is generally not an issue since the files are loaded locally anyways. However, Firefox does have a hard limit of 4MB per file ([1], [2]), which could prevent this solution from working on the Firefox Addons site.
Again, this is all outlined in various comments in the linked issue (#8071), which may the better place to track progress on a fix for this problem.
@mischnic Will this get priority? Jumping through the hoops just to make the basic f-nality work is distressing.