created: 2021-07-23T14:51:53.000Z

p-map で Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

p-map でエラーが出るようになった。

⚠  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users//node_modules/p-map/index.js
require() of ES modules is not supported.
require() of /Users//node_modules/p-map/index.js from /Users//lib/job/scrape-work-status/worker.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change

issueになっているが、とてもそっけない

Please read the release notes.

リリースノートに書いてあった。 Please read this とのこと。

Breaking This package is now pure ESM. Please read this.

対応

これ自体は悪い決断ではないと思うが、パッケージの利用者にはtree-shakingとか以外には大きなメリットはない変更である。 p-map はとてもシンプルなライブラリなので機能追加もなく、もうしばらく過去のバージョンにて利用を続けることにした。

yarn add p-map@4

参考

systemdの思想と機能 Linuxを支えるシステム管理のためのソフトウェアスイート (Software Design plusシリーズ)
[ad] systemdの思想と機能 Linuxを支えるシステム管理のためのソフトウェアスイート (Software Design plusシリーズ)
森若 和雄 (単行本(ソフトカバー))