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

TypeError: Cannot read property 'hash' of undefined #416

Open
pustovalov opened this issue Aug 3, 2018 · 99 comments · Fixed by scalableminds/webknossos#3239
Open

TypeError: Cannot read property 'hash' of undefined #416

pustovalov opened this issue Aug 3, 2018 · 99 comments · Fixed by scalableminds/webknossos#3239

Comments

@pustovalov
Copy link

pustovalov commented Aug 3, 2018

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()
)
@mzgoddard
Copy link
Owner

mzgoddard commented Aug 5, 2018

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

@pustovalov
Copy link
Author

pustovalov commented Aug 5, 2018

@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

@niieani
Copy link

niieani commented Aug 6, 2018

Same thing here:

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

@blackbird91
Copy link

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

@ndevvy
Copy link

ndevvy commented Aug 6, 2018

I am getting this error with webpack 4.16.4.

@nuintun
Copy link

nuintun commented Aug 8, 2018

Same problem

_20180808095205

@mrlescodes
Copy link

mrlescodes commented Aug 9, 2018

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

@7iomka
Copy link

7iomka commented Aug 14, 2018

any solutions? :(

@jamie-pi
Copy link

I'm having the same problem

@10ndavis
Copy link

Ditto.

@codart1
Copy link

codart1 commented Aug 17, 2018

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

@Mathieuu
Copy link

Same problem

@hannadrehman
Copy link

same here .. any one found the solution yet ?

@chrismwendt
Copy link

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.

@7iomka
Copy link

7iomka commented Aug 20, 2018

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

@pustovalov
Copy link
Author

pustovalov commented Aug 25, 2018

possible solution: fork this repository and merge this PR: #419

@evanstern
Copy link

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

@themojilla
Copy link

same problem after updating dep

@ricovitch
Copy link

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.

@pustovalov
Copy link
Author

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

@kevindurb
Copy link

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

@cchamberlain
Copy link

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

@antonellil
Copy link

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

@secabhi
Copy link

secabhi commented Oct 3, 2018

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

@Superjisan
Copy link

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

This worked for me, thanks my guy!

@AndrewBogdanovTSS
Copy link

@Superjisan you didn't fix anything. Just wait for a couple hours and you will get same problem over again. It will require you to delete the cache again and again. What is the purpose of this plugin than if you should always delete the cache and make a full rebuild?

@charithjayasanka
Copy link

Cleaning node_modules/.cache folder will do it

@garethweaver
Copy link

As recommended above we've been using hard-source-webpack-plugin-fixed-hashbug for a few months now and it's working great.

This is PR'd in #497 if you want to follow it.

@ansballard
Copy link

ansballard commented Aug 3, 2020

@kadamwhite from the recent activity it sounds like this PR: #497 from @conorh is probably a good candidate for checking and merging per your #525 issue. I don't have much free time these days but I'll see if I can take some time tonight to take a more recent look.

And it's been mentioned a couple times, but this thread is long enough that all the workarounds have been mentioned/disproved several times. If you're stumbling across this thread, be sure to read through before posting possible fixes, as there's already too much noise to be able to quickly understand what's been worked through already. Thanks!

Update: looked through the existing PR and the travis errors are just from the linter failing, mostly on code that's already committed in master, so I made a comment that as far as I can tell it's safe to merge.

@AndrewBogdanovTSS
Copy link

@garethweaver I've tried hard-source-webpack-plugin-fixed-hashbug in my project. At first, it was working as expected, but in couple of hours I've started to get the same error ☹

@Herz3h
Copy link

Herz3h commented Aug 24, 2020

Same error, only way I get to "solve it" is by removing cache folder, which makes this pointless if cache is removed all the time. So I removed this plugin from project since it seems unmaintained :/

@jvantuyl
Copy link

I think this is related to cache corruption. I didn't have this problem at all, then I experienced an out-of-memory error. After that, I got these errors until removing the cache folder as instructed above.

@lovemegowin
Copy link

lovemegowin commented Nov 28, 2020

Add follow code in you webpack.config.js can be resolve this issues

// webpack.config.js
...
config.plugins.push(
    new HardSourceWebpackPlugin.ExcludeModulePlugin([
      {
        test: /mini-css-extract-plugin[\\/]dist[\\/]loader/,
      }
    ])
  )
...

@AndrewBogdanovTSS
Copy link

@lovemegowin in what way should it resolve the issue? I had this config right from the start and it doesn't affect cache corruption what so ever

@freedyc
Copy link

freedyc commented Dec 11, 2020

My question:

Version: webpack 4.44.2
Time: 4624ms
Built at: 2020-12-11 10:44:07 AM
                                    Asset      Size  Chunks                                      Chunk Names
                                   app.js  4.43 MiB     app  [emitted]                    [big]  app
     fc7b2a59864448e6c572.hot-update.json  48 bytes          [emitted] [immutable] [hmr]
master.fc7b2a59864448e6c572.hot-update.js  4.12 KiB  master  [emitted] [immutable] [hmr]         master
                                master.js  9.71 MiB  master  [emitted]                    [big]  master
 + 3 hidden assets
Entrypoint app [big] = app.css app.js
[./assets/javascripts/zddi/am/dhcp_like/views/main.js] 2.67 KiB {master} [built]
    + 3749 hidden modules
ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...
[hardsource:19a950bb] Using 326 MB of disk space.
94% after seal[hardsource:19a950bb] Could not freeze ./assets/stylesheets/zddi.scss: Cannot read property 'hash' of undefined
[hardsource:19a950bb] Could not freeze ./node_modules/@dengyongchao/modal/modal.scss: Cannot read property 'hash' of undefined
ℹ 「wdm」: Hash: d41d03944d509d378704
Version: webpack 4.44.2
Time: 5698ms

The solution is add config

{
    new HardSourceWebpackPlugin(),
    new HardSourceWebpackPlugin.ExcludeModulePlugin([
        {
            // HardSource works with mini-css-extract-plugin but due to how
            // mini-css emits assets, assets are not emitted on repeated builds with
            // mini-css and hard-source together. Ignoring the mini-css loader
            // modules, but not the other css loader modules, excludes the modules
            // that mini-css needs rebuilt to output assets every time.
            test: /mini-css-extract-plugin[\\/]dist[\\/]loader/,
        },
    ]),
}

@0x1af2aec8f957
Copy link

0x1af2aec8f957 commented Jan 7, 2021

@freedyc
After my verification, this method is only effective in the first build, but not in the second build.
It is safe to delete the directory node_modules/.cache every time you build.

@VienArchway
Copy link

In nuxtjs app, I set into package.json

"scripts": {
    "clear-hard-source-cache": "rm -rf node_modules/.cache/hard-source/"
},

npm run clear-hard-source-cache

@AndrewBogdanovTSS
Copy link

@VienArchway how does it help to solve an issue? Such command makes this module pointless since you have to regenerate cache again and again

@xiaoxixi6633
Copy link

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

不是的 我的webpack 版本是4.0.0

@xiaoxixi6633
Copy link

I am getting this error with webpack 4.16.4.

I am getting this error with webpack 4.0.0.

@dazjean
Copy link

dazjean commented May 14, 2021

#461 (comment)
When I use this solution to solve the problem, it's an escape behavior to make other loaders work。

plugin:[
new HardSourceWebpackPlugin(),
new HardSourceWebpackPlugin.ExcludeModulePlugin({
            // HardSource works with mini-css-extract-plugin but due to how
            // mini-css emits assets, assets are not emitted on repeated builds with
            // mini-css and hard-source together. Ignoring the mini-css loader
            // modules, but not the other css loader modules, excludes the modules
            // that mini-css needs rebuilt to output assets every time.
            test: /mini-css-extract-plugin[\\/]dist[\\/]loader/
        })
]

@dazjean
Copy link

dazjean commented May 14, 2021

#461 (comment)
When I use this solution to solve the problem, it's an escape behavior to make other loaders work。

plugin:[
new HardSourceWebpackPlugin(),
new HardSourceWebpackPlugin.ExcludeModulePlugin({
            // HardSource works with mini-css-extract-plugin but due to how
            // mini-css emits assets, assets are not emitted on repeated builds with
            // mini-css and hard-source together. Ignoring the mini-css loader
            // modules, but not the other css loader modules, excludes the modules
            // that mini-css needs rebuilt to output assets every time.
            test: /mini-css-extract-plugin[\\/]dist[\\/]loader/
        })
]

我用的这个 方法 但是还是 有相同的问题,我看大部分人都不再提问了,我也很纳闷

new HardSourceWebpackPlugin() 必须在之前被使用添加到plugin中。

@huoyuxin
Copy link

huoyuxin commented Jun 9, 2021

here is a possible solution. please check~ @pustovalov @mzgoddard
#519

@pustovalov
Copy link
Author

I stopped using this plugin after I found this behavior: #416 (comment)

@recover758126
Copy link

I use this solution to fix the problem, but it is not work, I get the same error after few moments
plugin:[ new HardSourceWebpackPlugin(), new HardSourceWebpackPlugin.ExcludeModulePlugin({ // HardSource works with mini-css-extract-plugin but due to how // mini-css emits assets, assets are not emitted on repeated builds with // mini-css and hard-source together. Ignoring the mini-css loader // modules, but not the other css loader modules, excludes the modules // that mini-css needs rebuilt to output assets every time. test: /mini-css-extract-plugin[\\/]dist[\\/]loader/ }) ]

@brainz80
Copy link

brainz80 commented Aug 3, 2021

Decided to switch to webpack 5. Webpack 5 has built-in filesystem caching.

use cache: false to disable it.

And

cache: {
	cacheDirectory: path.resolve(__dirname, 'node_modules/.cache/.temp_cache'),
	type: 'filesystem',
}

to define a filesystem cache. Cached data will be stored in cacheDirectory.

More info here https://webpack.js.org/configuration/cache/#cache
and here #546

@laniltee
Copy link

I had the same issue with NextJS "next": "11.1.2", "react": "17.0.2" and "react-dom": "17.0.2". Removing node_modules directory, Removing package-lock.json and re-running npm run build after npm install worked.

@RyanClementsHax
Copy link

I had the same issue with NextJS "next": "11.1.2", "react": "17.0.2" and "react-dom": "17.0.2". Removing node_modules directory, Removing package-lock.json and re-running npm run build after npm install worked.

I had the same exact issue with the same exact versions and the solution was exactly the same (I use yarn instead of npm, but it worked just fine)

@AndrewBogdanovTSS
Copy link

I had the same issue with NextJS "next": "11.1.2", "react": "17.0.2" and "react-dom": "17.0.2". Removing node_modules directory, Removing package-lock.json and re-running npm run build after npm install worked.

I had the same exact issue with the same exact versions and the solution was exactly the same (I use yarn instead of npm, but it worked just fine)

it's not a solution at all, you just removed cache folder together with nuking node_modules so of course you don't see an error anymore since new cache is created but that makes this module useless with such "solutions"

@wesleybl
Copy link

wesleybl commented Apr 7, 2022

I didn't have this problem but unexpectedly it started to occur:

[hardsource:15122d4d] Could not freeze ./app/img/resize-hor.png: Cannot read property 'fileDependencies' of undefined

I then realized that I had a node_modules folder on my home. So I deleted it and the error was gone.

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