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

Cached value is 'null' in CacheMd5 when @require in stylus #330

Closed
piecyk opened this issue May 21, 2018 · 7 comments
Closed

Cached value is 'null' in CacheMd5 when @require in stylus #330

piecyk opened this issue May 21, 2018 · 7 comments
Labels

Comments

@piecyk
Copy link
Contributor

piecyk commented May 21, 2018

Expected Behavior

Should not throw an exception

Actual Behavior

Throws an exception

Is an error being thrown?

✖ 「wdm」: TypeError: Cannot read property 'hash' of null
    at Object.keys.forEach.key (/Users/piecyk/work/web/node_modules/hard-source-webpack-plugin/lib/CacheMd5.js:209:48)
    at Array.forEach (<anonymous>)
    at md5CacheSerializer.read.then.then._md5Cache (/Users/piecyk/work/web/node_modules/hard-source-webpack-plugin/lib/CacheMd5.js:204:36)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Steps to Reproduce

Basic when changing styles in some Gloabl.styl that looks like

@require 'lib/css/fonts'
html
  margin 0

Hard source will throw with the exception above, when change margin
for example to 10px on next run... Looks like the cached value is null

Will dig more, current when patching this with piecyk@f6268f1
everything works as expected

Essential package.json

"webpack": "4.8.3",
"hard-source-webpack-plugin": "0.7.0-alpha.3",
"stylus-loader": "3.0.2",

webpack config stylus rule

{
  test: /\.styl$/,
  use: [
    MiniCssExtractPlugin.loader,
    {loader: 'css-loader', options: cssOptions},
    {loader: 'postcss-loader', options: postcssOptions},
    {
      loader: 'stylus-loader',
      options: {
        'resolve url': true,
        paths: 'src',
        preferPathResolver: 'webpack',
        import: [path.resolve(srcPath, 'lib', 'css', 'global_mixins.styl')],
        sourceMap: false
      }
    }
  ]
},
@piecyk
Copy link
Contributor Author

piecyk commented May 21, 2018

hmm it looks like values are set, but on next run...
It's not removed from unbuildMd5s that's way ti's null 🤔

@mzgoddard
Copy link
Owner

@piecyk I think this is caused by the new data serializer because of a small incorrect detail that'll be easy to fix. If you run with new HardSourceWebpackPlugin.HardSourceAppendSerializerPlugin() (the previous default) and do not encounter the error, we'll be able to confirm its incorrect data coming from the new default.

I'm replacing the old default primarily for stability. The old default has a few race conditions that have been difficult to hunt down, causing some builds to fail that otherwise normally do not. The new default cleans that up by taking a different but still fast approach (compared to other cache layers I've tried) that is actually unexpectedly faster than the old default.

@piecyk
Copy link
Contributor Author

piecyk commented May 21, 2018

Yeah 👍 it looks like path madness, basic here

unbuildMd5s[key] = null;

key is an absolute path set to null for example
unbuildMd5s['/Users/piecyk/work/web/src/lib/css/fonts.styl'] = null

but here, where we want to remove it, file path is relative

delete unbuildMd5s[file];

it's delete unbuildMd5s['src/lib/css/fonts.styl'];
that's way it's not removed, hmm it would be good to normalize the file paths ...

Overall @mzgoddard awesome changes, much more easy to follow what is happening 👏

@piecyk
Copy link
Contributor Author

piecyk commented May 21, 2018

running it like this

  new HardSourceWebpackPlugin({
    cacheDirectory: path.resolve(webpackCacheDir, 'hard-source/[confighash]'),
  }),
  new HardSourceWebpackPlugin.SerializerAppendPlugin(),

the same output

No cached value for key = /Users/piecyk/work/web/src/lib/css/fonts.styl

@piecyk
Copy link
Contributor Author

piecyk commented May 22, 2018

It looks like when normalize the file path between _hardSourceWriteCache and _hardSourceReadCache it works... Basic in write you use relateNormalPath but in read contextNormalPath hmm question what choose here?

md5Cache cachedMd5s unbuildMd5s need to have the same keys

@mzgoddard
Copy link
Owner

@piecyk Does #332 answer this issue?

@piecyk
Copy link
Contributor Author

piecyk commented May 28, 2018

Yeah it's resolved 👍 thanks @mzgoddard

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

No branches or pull requests

2 participants