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.