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

Jul 23, 2021 23:51 · 281 words · 1 minute read

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

参考

tweet Share