hard-source-webpack-plugin icon indicating copy to clipboard operation
hard-source-webpack-plugin copied to clipboard

TypeError: Cannot read property 'hash' of undefined

Open pustovalov opened this issue 7 years ago • 99 comments

Expected Behavior

Successful compilation from the first time

Actual Behavior

The first compilation failed, the second successful

Is an error being thrown?

debug:

function updateMd5CacheItem(value) {
  if (md5Cache[file]) {
    console.log('file', file)
    console.log('md5Cache[file]', md5Cache[file])
    console.log('value', value)
  }
  if (
    !md5Cache[file] ||
    (md5Cache[file] && md5Cache[file].hash !== value.hash)
  ) {

log:

file /app/assets/stylesheets/themes/shared/_flex.scss
md5Cache[file] { mtime: 1533291733713,
  hash: 'a57c36d6619fa2b99458d0f2d4045d74',
  isFile: true,
  isDirectory: false }
value { mtime: 1533291735643,
  hash: 'a57c36d6619fa2b99458d0f2d4045d74',
  isFile: true,
  isDirectory: false }
file /vendor/assets/stylesheets/_spaces.sass
md5Cache[file] { mtime: 1533291734298,
  hash: '24f5e6afc9adbd8007d9bb8aaf881ddb',
  isFile: true,
  isDirectory: false }
value { mtime: 1533291735643,
  hash: '24f5e6afc9adbd8007d9bb8aaf881ddb',
  isFile: true,
  isDirectory: false }
file /app/assets/stylesheets/application_v2/_config.sass
md5Cache[file] { mtime: 1533291733710,
  hash: '70d356e279b46ee8dc81ab0173772507',
  isFile: true,
  isDirectory: false }
value undefined
file /app/assets/stylesheets/themes/shared/_utils.sass
md5Cache[file] { mtime: 1533291733712,
  hash: 'b151941279dbf615b1cc28bfcded8f38',
  isFile: true,
  isDirectory: false }
value undefined
TypeError: Cannot read property 'hash' of undefined
    at updateMd5CacheItem (/node_modules/hard-source-webpack-plugin/lib/CacheMd5.js:373:66)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Steps to Reproduce

just run webpack-dev-server

Operating System, Node, and NPM dependency versions

Mac OS 10.13.6
Node 10.7.0
webpack: 3.12.0
hard-source-webpack-plugin 0.12.0

"dependencies": {
  "@rails/webpacker": "3.5",
  "at.js": "^1.5.3",
  "autoprefixer": "^8.x",
  "babel-plugin-dynamic-import-webpack": "^1.0.2",
  "babel-plugin-styled-components": "^1.5.1",
  "babel-plugin-transform-decorators-legacy": "^1.3.4",
  "babel-plugin-transform-do-expressions": "^6.22.0",
  "babel-polyfill": "^6.26.0",
  "babel-preset-env": "^1.6.0",
  "babel-preset-react": "^6.24.1",
  "babel-preset-stage-2": "^6.24.1",
  "balloon-css": "^0.5.0",
  "caniuse-lite": "^1.0.30000697",
  "cjsx-loader": "^3.0.0",
  "classnames": "^2.2.5",
  "clipboard": "^2.0.1",
  "coffee-loader": "^0.9.0",
  "coffeescript": "^2.3.1",
  "compression-webpack-plugin": "^1.0.0",
  "create-react-class": "^15.6.3",
  "dropzone": "^5.3.0",
  "expose-loader": "^0.7.3",
  "filesize": "^3.6.1",
  "glob": "^7.1.2",
  "highcharts": "^6.0.4",
  "highlight.js": "9.12.0",
  "jquery": "^1.12.3",
  "jquery.caret": "^0.3.1",
  "js-yaml": "^3.9.1",
  "lodash": "^4.17.10",
  "mobx": "^4.3.1",
  "mobx-devtools-mst": "^0.9.18",
  "mobx-react": "^5.2.3",
  "mobx-react-form": "^1.32.2",
  "mobx-react-form-devtools": "^1.7.2",
  "mobx-state-tree": "^2.2.0",
  "moment-timezone": "^0.5.14",
  "node-sass": "^4.8.3",
  "path-complete-extname": "^0.1.0",
  "pluralize": "^7.0.0",
  "postcss-smart-import": "^0.7.5",
  "precss": "^2.0.0",
  "prop-types": "^15.6.0",
  "query-string": "^5.1.0",
  "rails-erb-loader": "^5.4.2",
  "react": "^16.2.0",
  "react-bootstrap": "0.31.5",
  "react-dom": "^16.2.0",
  "react-helmet": "^5.2.0",
  "react-loadable": "^5.3.1",
  "react-router-dom": "^4.3.1",
  "react-router-navigation-prompt": "^1.5.5",
  "react-scroll": "^1.7.9",
  "react-simple-colorpicker": "^1.x",
  "react-textarea-autosize": "^6.1.0",
  "resolve-url-loader": "^2.1.0",
  "sass-loader": "^7.0.3",
  "sortablejs": "^1.7.0",
  "stickyfilljs": "^2.0.3",
  "styled-components": "3.2.6",
  "stylelint": "^8.3.0",
  "stylelint-config-standard": "^18.0.0"
},
"devDependencies": {
  "babel-eslint": "^8.2.3",
  "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
  "enzyme": "^3.3.0",
  "enzyme-adapter-react-16": "^1.1.1",
  "eslint": "^4.19.1",
  "eslint-config-standard": "^10.2.1",
  "eslint-config-standard-react": "^5.0.0",
  "eslint-plugin-babel": "^4.1.2",
  "eslint-plugin-import": "^2.7.0",
  "eslint-plugin-node": "^5.1.1",
  "eslint-plugin-promise": "^3.5.0",
  "eslint-plugin-react": "^7.3.0",
  "eslint-plugin-standard": "^3.0.1",
  "hard-source-webpack-plugin": "^0.12.0",
  "jest": "^23.2.0",
  "jest-enzyme": "^6.0.2",
  "jest-html": "^1.4.0",
  "jest-serializer-enzyme": "^1.0.0",
  "jest-serializer-html": "^5.0.0",
  "jest-styled-components": "^5.0.1",
  "mobx-devtools-mst": "^0.9.18",
  "prettier": "^1.7.4",
  "webpack-bundle-analyzer": "^2.10.0",
  "webpack-dev-server": "2.11.2"
},

plugin configuration:

const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
environment.plugins.prepend('HardSourceWebpackPlugin',
  new HardSourceWebpackPlugin()
)

pustovalov avatar Aug 03 '18 10:08 pustovalov

@pustovalov can you confirm that _config.sass or _utils.sass appear only once in the debug output? I'm wondering if they are somehow trying to update their hashes twice. I'm not sure how that could happen though.

mzgoddard avatar Aug 05 '18 12:08 mzgoddard

@mzgoddard debug:

            function updateMd5CacheItem(value) {
              if (file.includes('_config.sass')) {
                console.log('file', file)
              }

output:

404s will fallback to /index.html
[hardsource:de83c073] Tracking node dependencies with: yarn.lock.
 69% building modules 1690/1696 modules 6 active .../bundles/customer-service-portal.scssfile /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
 94% asset optimizationfile /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
TypeError: Cannot read property 'hash' of undefined
    at updateMd5CacheItem (/node_modules/hard-source-webpack-plugin/lib/CacheMd5.js:376:66)
    at process._tickCallback (internal/process/next_tick.js:68:7)

second run:

[hardsource:de83c073] Using 39 MB of disk space.
[hardsource:de83c073] Tracking node dependencies with: yarn.lock.
[hardsource:de83c073] Reading from cache de83c073...
[hardsource:de83c073] Last compilation did not finish saving. Building new cache.
 69% building modules 1690/1696 modules 6 active .../bundles/customer-service-portal.scssfile /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
 69% building modules 1691/1696 modules 5 active .../bundles/customer-service-portal.scssfile /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
 94% asset optimizationfile /app/assets/stylesheets/application_v2/_config.sass
file /app/assets/stylesheets/application_v2/_config.sass
Hash: b484f5d81fb0e1e4058b
Version: webpack 3.12.0
Time: 17763ms

pustovalov avatar Aug 05 '18 19:08 pustovalov

Same thing here:

[hardsource:6f72a45a] Could not freeze ./app-entries/settings.js + 23 modules: Cannot read property 'hash' of undefined

niieani avatar Aug 06 '18 13:08 niieani

Same problem here. This issue seems to appear after the latest webpack update (4.16.4 -> 4.16.5)

blackbird91 avatar Aug 06 '18 13:08 blackbird91

I am getting this error with webpack 4.16.4.

ndevvy avatar Aug 06 '18 18:08 ndevvy

Same problem

_20180808095205

nuintun avatar Aug 08 '18 01:08 nuintun

I was getting the same issue as well, deleting the hard-source cache folder from /node_modules/.cache/hard-source/ has fixed this for me and it has yet to re-appear after more dev on the project. Not sure what caused it in the first place however...

before after

mrlescodes avatar Aug 09 '18 17:08 mrlescodes

any solutions? :(

7iomka avatar Aug 14 '18 10:08 7iomka

I'm having the same problem

jamie-pi avatar Aug 15 '18 11:08 jamie-pi

Ditto.

10ndavis avatar Aug 16 '18 12:08 10ndavis

Same here

[hardsource:748ccae8] Could not freeze ./node_modules/xtend/immutable.js: Cannot read property 'hash' of undefined
[hardsource:748ccae8] Could not freeze ./node_modules/zen-observable-ts/lib/index.js: Cannot read property 'hash' of undefined
[hardsource:748ccae8] Could not freeze ./node_modules/zen-observable-ts/lib/zenObservable.js: Cannot read property 'hash' of undefined
[hardsource:748ccae8] Could not freeze ./node_modules/zen-observable-ts/node_modulesWebpack: Starting ...

codart1 avatar Aug 17 '18 13:08 codart1

Same problem

Mathieuu avatar Aug 17 '18 16:08 Mathieuu

same here .. any one found the solution yet ?

hannadrehman avatar Aug 19 '18 19:08 hannadrehman

Removing node-sass-import-once in one of my projects seems to fix it, but the CSS output is different and it broke the UI.

chrismwendt avatar Aug 20 '18 00:08 chrismwendt

Latest version broke usage of browsersync plugin (auto-inject css not works as expected, long time, and multiple reloads) Version of hardsource which I now use instead of the last (to somehow work) is ^0.6.4 I'm sad

7iomka avatar Aug 20 '18 01:08 7iomka

possible solution: fork this repository and merge this PR: https://github.com/mzgoddard/hard-source-webpack-plugin/pull/419

pustovalov avatar Aug 25 '18 13:08 pustovalov

The solution from @MrLesAubrey has worked for me so far. I guess if I see this error again I'll just do as he recommended (remove the contents of node_modules/.cache/hard-source directory).

evanstern avatar Aug 29 '18 20:08 evanstern

same problem after updating dep

themojilla avatar Aug 30 '18 10:08 themojilla

Same problem for me here. It happens very often when i update some dependencies while the wepack dev server is started. I tested a workaround using a postinstall script in package.json to clear the cache folder, but i'm not totally sure of the results.

ricovitch avatar Aug 31 '18 15:08 ricovitch

you can try to use this in package.json:

{
  "hard-source-webpack-plugin": "https://github.com/talkable/hard-source-webpack-plugin#build",
}

but it's better to use your own fork

pustovalov avatar Aug 31 '18 15:08 pustovalov

Im also gettng this error too. It goes away for a bit when i delete my cache folder but then will come back seemingly randomly

kevindurb avatar Sep 04 '18 13:09 kevindurb

@pustovalov just forked yours and it worked first try. Haven't done enough testing to see if it will come back but I had a complete blocking issue after installing webpack-watch-files-plugin which I couldn't progress past prior to forking so thanks!

cchamberlain avatar Sep 17 '18 20:09 cchamberlain

I am seeing this error as well Could not freeze /path/to/file: Cannot read property 'hash' of undefined, noticed that it seems to be happening only for files which contain async-loaded imports, or are dependencies of async-loaded imports

antonellil avatar Sep 27 '18 21:09 antonellil

Even this error is occurring the build is working fine for me. At least its not breaking anything . If its breaking anything please let me know

secabhi avatar Oct 03 '18 08:10 secabhi

It's breaking my build. I am not using nextjs in this project but I do have a bunch of custom webpack stuff. It ends up aborting the output and just says waiting for bundling. I am going to disable the cache until it's fixed I guess.

richtera avatar Oct 05 '18 19:10 richtera

Not sure why this works, or whether it will for anyone else, but our package-lock.json in our repo was unversioned for some reason and mine seemed to be causing me more problems than my colleague's. Once he versioned his package-lock.json I replaced mine and I don't seem to be having as many problems now. Make of it what you will.

jamie-pi avatar Oct 08 '18 08:10 jamie-pi

same problem~

xwchris avatar Oct 17 '18 01:10 xwchris

We've been running into this too, I just had to remove this plugin from one of our projects to unblock a client team. I agree that merging #419 seems like a good path forward; @mzgoddard is there anything I can do to assist or test?

kadamwhite avatar Nov 06 '18 21:11 kadamwhite

Same problem here, removing the cache solved the issue. How far out are we from releasing the fix? We are running a big team of devs and we are starting to get this issue more frequently than we want to.

MateusDantas avatar Nov 14 '18 11:11 MateusDantas

@MateusDantas have you tried this way https://github.com/mzgoddard/hard-source-webpack-plugin/issues/416#issuecomment-417699776?

pustovalov avatar Nov 14 '18 11:11 pustovalov