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

参考

CAREER SKILLS ソフトウェア開発者の完全キャリアガイド
[ad] CAREER SKILLS ソフトウェア開発者の完全キャリアガイド
ジョン・ソンメズ, 長尾 高弘 (Kindle版)