Closed SSANSH closed 3 years ago
Please read the release notes.
@SSANSH In case you were still wondering: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
Same problem. I use pMap by
const pMap = require('p=map');
Howerver, it reports like this:
internal/modules/cjs/loader.js:1085
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:
I tried to move my CommonJS project to ESM like this said https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
The problem is that some libraries that I used cannot be moved to ESM. So, What should I do?
The problem is that some libraries that I used cannot be moved to ESM.
Importing CommonJS packages from ESM will still work.
@Richienb Could you please shed some light on it? I'm using NestJS which is incompetible with ESM. Is there any workaround to use p-map
v5?
@dzcpy If you want to use the package, you'll either need to discover a way to load ESM modules in NestJS or use an older version.
const pMap = (...args)=>import('p-map').then(({default: pMap})=>pMap(...args));
const pMap = (...args)=>import('p-map').then(({default: pMap})=>pMap(...args));
Why do you even need p-map
in the first place then :)
const pMap = (array, func) => Promise.all(array.map(func));
p-map is most useful for its extra features like custom concurrency and for the abstraction it provides.
Hello all. I've created a util to convert ESM-only packages to CJS, for those who need it. This is still very much a work in progress, so please open an issue on the repository with any feedback.
This package (p-map@5.5.0
) can be installed as CJS via @cjs-exporter/p-map
.
@isaachinman fantastic! could you please make the same for p-retry
please?
@art1c0 Sure thing, here you go.
Hilarious that this still causes friction over three years later.
I bump my service which are using p-map for testing from version 4.0.0 to 5.0.0 and now I got the following issue during my test.
node version v14.16.0
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: .../node_modules/p-map/index.js require() of ES modules is not supported. require() of .../node_modules/p-map/index.js from ..../tests/contracts/step_definitions/test.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 the requiring code to use import(), or remove "type": "module" from .../node_modules/p-map/package.json.
is is a breaking change not documented? if yes how I can fix then
note I use pMap using import
import pMap from 'p-map';