hard-source-webpack-plugin
hard-source-webpack-plugin copied to clipboard
TypeError: Cannot read property 'hash' of undefined
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 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 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
Same thing here:
[hardsource:6f72a45a] Could not freeze ./app-entries/settings.js + 23 modules: Cannot read property 'hash' of undefined
Same problem here. This issue seems to appear after the latest webpack update (4.16.4 -> 4.16.5)
I am getting this error with webpack 4.16.4.
Same problem

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

any solutions? :(
I'm having the same problem
Ditto.
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 ...
Same problem
same here .. any one found the solution yet ?
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.
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
possible solution: fork this repository and merge this PR: https://github.com/mzgoddard/hard-source-webpack-plugin/pull/419
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).
same problem after updating dep
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.
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
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
@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!
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
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
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.
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.
same problem~
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?
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 have you tried this way https://github.com/mzgoddard/hard-source-webpack-plugin/issues/416#issuecomment-417699776?