LoginSignup
16

More than 3 years have passed since last update.

ビルドすると「Could not freeze ./.nuxt/router.js: Cannot read property 'hash' of undefined」が出る

Last updated at Posted at 2020-08-01

結論

hardSourceで作成されたキャッシュを消してください。

$ rm -rf node_modules/.cache/hard-source/

解説

ビルドするとこんな感じのエラーが出た

ERROR  [hardsource:a105875d] Could not freeze ./.nuxt/router.js: Cannot read property 'hash' of undefined

nuxt.config.jsで指定したキャッシュ設定が原因

export default {
  build: {
    // ビルド高速化の為にキャッシュしてる
    hardSource: true,
  }
}

キャッシュファイルを削除しよう

ただキャッシュファイルを消すだけ

$ rm -rf node_modules/.cache/hard-source/

よく使うのでpackage.jsonでscript化しておこう

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

こんな感じで使う

$ yarn clear-hard-source-cache

参考

https://github.com/mzgoddard/hard-source-webpack-plugin/issues/416
https://blog.mintsu-dev.com/posts/2019-08-22-nuxtjs-build-performance/

追記 2020/11/12

hardSourceは使わない方がいいかも

hardSourceでキャッシュしてローカルビルドを早くするのは、
公式がベータ版と言っている通り不具合が多くやらない方が良いかも知れません。

もしもローカルのビルド時間が長い場合

  • dockerなどを使っていれば与えるメモリ容量を増やす
  • dockerなどを使わずにローカルのnodeでビルドする
  • バンドルサイズが大きい場合はそもそもの無駄コードを減らす(重複など)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16