Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot read property 'hashReferences' of undefined #4145

Open
kevincox opened this issue Feb 16, 2020 · 48 comments
Open

Error: Cannot read property 'hashReferences' of undefined #4145

kevincox opened this issue Feb 16, 2020 · 48 comments

Comments

@kevincox
Copy link
Contributor

kevincox commented Feb 16, 2020

🐛 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
@mischnic
Copy link
Member

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

@kevincox
Copy link
Contributor Author

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)

@Banou26
Copy link
Contributor

Banou26 commented Feb 19, 2020

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.

@kevincox
Copy link
Contributor Author

kevincox commented Feb 19, 2020

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.

@padmaia
Copy link
Contributor

padmaia commented Feb 20, 2020

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.

@padmaia
Copy link
Contributor

padmaia commented Feb 20, 2020

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

@ubershmekel
Copy link

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)

@brettinternet
Copy link

brettinternet commented Jul 5, 2020

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)

@mischnic
Copy link
Member

mischnic commented Jul 6, 2020

Can someone else confirm that this is fixed?

@ross-pfahler
Copy link

ross-pfahler commented Jul 8, 2020

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.

@schlagi123
Copy link

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.

@RPDeshaies
Copy link

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

@cifkao
Copy link

cifkao commented Aug 15, 2020

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.

@cifkao
Copy link

cifkao commented Aug 15, 2020

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

@mischnic
Copy link
Member

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....

@cifkao
Copy link

cifkao commented Aug 15, 2020

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.

lgarron added a commit to cubing/cubing.js that referenced this issue Aug 16, 2020
@mischnic
Copy link
Member

mischnic commented Aug 17, 2020

At least in @cifkao's example, this is caused by inline bundles not being processed (as they shouldn't)

let bundles = bundleGraph.getBundles().filter(bundle => !bundle.isInline);

so bundleInfoMap[someInlineBundle.id] is undefiend.
But they are still listed in the hashReferences of their parent bundles:
for (let hashRef of bundleInfoMap[bundleId].hashReferences) {

and then bundleInfoMap[someInlineBundle.id].hashReferences fails. I'm not quite sure if they should just be skipped or handled in some other way.

@dgkimpton
Copy link

dgkimpton commented Aug 20, 2020

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)

@SpeedySH
Copy link

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?

@arb000r
Copy link

arb000r commented Aug 30, 2020

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

EDIT: Latest nightly is working

@jeffpeck10x
Copy link
Contributor

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? 🤷

@mischnic
Copy link
Member

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;

@artemjackson
Copy link

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

@ghost
Copy link

ghost commented Jun 16, 2021

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.

@devongovett devongovett added this to the v2.0.0-rc.0 milestone Jul 8, 2021
@devongovett
Copy link
Member

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?

@devongovett
Copy link
Member

Going to close this since it seems to be working now. If you manage to reproduce it still, please let us know.

@kevincox
Copy link
Contributor Author

kevincox commented Oct 14, 2021

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

@mischnic mischnic reopened this Oct 14, 2021
@danieltroger
Copy link
Contributor

danieltroger commented Jan 31, 2022

Also experiencing this issue when trying to workaround #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)

@danieltroger
Copy link
Contributor

For me, falling back to fs.readFileSync worked as an ugly workaround :)

@Stvad
Copy link

Stvad commented Apr 29, 2022

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

@Stvad
Copy link

Stvad commented Apr 29, 2022

For me falling back on fs does not work, as I actually want Parcel to process imports in the CSS first =\
shoonia/parcel-transformer-css-to-string#6 does not work for similar reasons =\

@Stvad
Copy link

Stvad commented Apr 29, 2022

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",

@Stvad
Copy link

Stvad commented Apr 29, 2022

so removing --no-hmr seems to have resolved this for me 🤷‍♂️

@Stvad
Copy link

Stvad commented May 8, 2022

But if I were to remove --no-content-hash from the build command, I start hitting this issue in the build command 🙈

@calclavia
Copy link

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

@everdimension
Copy link

everdimension commented Jul 4, 2022

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)

@avalanche1
Copy link

Has anyone been able to circumvent the issue?
Because the --no-content-hash solution, as stated by @everdimension , doesn't really work.

@Stvad
Copy link

Stvad commented Jul 19, 2022

@everdimension @avalanche1 I think you may be hitting another bug - see #8071

@mark-monteiro
Copy link

@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.

@mark-monteiro
Copy link

mark-monteiro commented Aug 29, 2022

@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.

@avalanche1
Copy link

@mischnic Will this get priority?
Jumping through the hoops just to make the basic f-nality work is distressing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.