TypeError: concurrently(...).then is not a function

I got message"TypeError: concurrently(…).then is not a function",the code is \odyssey-voyage-II-server-main\monolith\utils\launch:"

const concurrently = require(‘concurrently’);
const path = require(‘path’);
concurrently(
[
{
command: ‘npm start’,
name: ‘accounts’,
cwd: path.resolve(__dirname, ‘…/…/services/accounts’),
prefixColor: ‘blue’,
},
{
command: ‘npm start’,
name: ‘listings’,
cwd: path.resolve(__dirname, ‘…/…/services/listings’),
prefixColor: ‘magenta’,
},
{
command: ‘npm run booking:update’,
name: ‘bookings’,
cwd: path.resolve(__dirname, ‘…/…/services/bookings’),
prefixColor: ‘green’,
},
],
{
prefix: ‘name’,
killOthers: [‘failure’],
restartTries: 3,
}
).then(
function onSuccess() {
// This code is necessary to make sure the parent terminates
// when the application is closed successfully.
process.exit();
},
function onFailure(exitInfo) {
console.log(exitInfo);
// This code is necessary to make sure the parent terminates
// when the application is closed because of a failure.
process.exit();
}
);

"

chatgpt
The error message you received, “TypeError: concurrently(…).then is not a function,” suggests that the concurrently function does not return a promise that can be chained with .then().

In the code you provided, it seems that you are using the concurrently package to run multiple commands concurrently. The concurrently function does not return a promise by default, so you cannot use .then() on it.

If you want to execute some code after the concurrently operation is completed, you can provide a callback function as the third argument to the concurrently function. Here’s an updated version of your code:

javascript
Copy code
const concurrently = require(‘concurrently’);
const path = require(‘path’);

concurrently(
[
{
command: ‘npm start’,
name: ‘accounts’,
cwd: path.resolve(__dirname, ‘…/…/services/accounts’),
prefixColor: ‘blue’,
},
{
command: ‘npm start’,
name: ‘listings’,
cwd: path.resolve(__dirname, ‘…/…/services/listings’),
prefixColor: ‘magenta’,
},
{
command: ‘npm run booking:update’,
name: ‘bookings’,
cwd: path.resolve(__dirname, ‘…/…/services/bookings’),
prefixColor: ‘green’,
},
],
{
prefix: ‘name’,
killOthers: [‘failure’],
restartTries: 3,
},
(exitCodes, signal) => {
if (exitCodes && exitCodes.some(code => code !== 0)) {
console.log(‘Error occurred during execution.’);
process.exit(1);
} else {
console.log(‘All commands completed successfully.’);
process.exit(0);
}
}
);
In this updated code, the callback function (exitCodes, signal) => { … } is called once the concurrently operation is finished. It checks the exitCodes to determine if any command failed (exit code is not 0), and then you can handle the success or failure accordingly.

Note that the exit() calls within the callback are necessary to ensure that the parent process terminates when the application is closed successfully or due to a failure.

Hi @xibaozhi0 ! This typically happens when you haven’t installed the necessary packages.

In the monolith folder, make sure to run npm i. Then, run npm run launch to start the services.

Can you also confirm what version of node you’re using with node -v?

Hope that helps!

sorry, I use node 18.16.0. maybe I use command “npm start” first. serval month ago, I did not meet any error message, this time an error message came to me. sorry

No worries! Is it working for you after running npm i then npm run launch in the monolith folder? Or are you still stuck with that error?