How to import in commonjs?
galaczi opened this issue · comments
Hi, how would I use this package in commonjs?
const ProcessConcurrently = require('iterate-async').default; // don't forget the 'default'!
ProcessConcurrently(async (item) => {
await Promise.resolve(); // do something async
return item * 2;
}, [1, 2, 3, 4, 5, 6]).then(
result => console.log(result)
// result = [2, 4, 6, 8, 10, 12]
);
Be sure to use the currently latest version 1.1.2 (before this version you used to have to import using the path).
I've also added this snippet to the README now :)
Thanks for the quick reply! However, running the exact code you gave results in:
Uncaught TypeError TypeError: ProcessConcurrently is not a function
at <anonymous> (/project/concurrencyTest.js:3:1)
at Module._compile (node:internal/modules/cjs/loader:1099:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Module._load (node:internal/modules/cjs/loader:822:12)
at executeUserEntryPoint (node:internal/modules/run_main:77:12)
at <anonymous> (node:internal/main/run_main_module:17:47)
I am on Node v17.9.0.
Can you check your package.json and verify that you have at least version 1.1.2?
Before 1.1.2, it used to be const ProcessConcurrently = require('iterate-async/build/index.cjs').default;
.
I tried last night and it worked fine for me, however that, I'm going to have a look asap if I can reproduce with node 17, yesterday I didn't check what version if node I was using.
Works just fine for me using exactly Node v17.9.0, I can't reproduce - again, make sure you use at least v1.1.2 as seen in the package.json below. (My try yesterday in which I couldn't reproduce was Node 16.)
package.json
{
.......
"dependencies": {
"iterate-async": "^1.1.2"
}
}
'+ npm install
(also tried with yarn, works fine).
index.js and index.cjs (I tried both)
const ProcessConcurrently = require('iterate-async').default;
ProcessConcurrently(async (item) => {
await Promise.resolve(); // do something async
return item * 10;
}, [1, 2, 3, 4, 5, 6]).then(
result => console.log(result)
);
'+ node index.js
/ node index.cjs
I had 1.1.0 installed. Upgrading to 1.1.2 solved it. Thank you!