npm startするとCan’t resolve ‘assert’エラー

おそらく、webpackを4系から5系にアップデートした影響(?)で発生したエラーと思われる。

(参考)現在利用しているバージョン:webpack 5.65.0

現象

npm startすると以下のエラー。

% npm start
Compiled with problems:
ERROR in ./node_modules/@project-serum/anchor/dist/browser/index.js 12:0-28
Module not found: Error: Can’t resolve ‘assert’ in ‘/Users/user/Desktop/blockchain/bbb/node_modules/@project-serum/anchor/dist/browser’
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
    - add a fallback ‘resolve.fallback: { “assert”: require.resolve(“assert/“) }’
    - install ‘assert’
If you don’t want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { “assert”: false }

原因

polyfillがデフォルトでインストールされなくなったため、環境にあわせて各自で対応が必要になった。自分のケースは assert が見つからないと言われている。

対応

今回はassertが見つからないだけなので、assertをインストールして完了した。

% npm install assert