#I got and error when i compile my ts project and using pm2 start ecosystem.config.js command

7 messages · Page 1 of 1 (latest)

twin tundra

My code:
ecosystem.config.js:

const bots = [
    {
        name: "Management",
        namespace: "TitanLion",
        script: "main.js",
        watch: true,
        exec_mode: "cluster",
        max_memory_restart: "2G",
        cwd: "./Bots/Management",
    },
];
export default {
    apps: bots,
};
//# sourceMappingURL=ecosystem.config.js.map

Error:

PS C:\Users\yenil\Desktop\new-v14-shield> cd sources
PS C:\Users\yenil\Desktop\new-v14-shield\sources> pm2 start ecosystem.config.js
[PM2][ERROR] File ecosystem.config.js malformated
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\yenil\Desktop\new-v14-shield\sources\ecosystem.config.js from C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\Common.js not supported.
Instead change the require of ecosystem.config.js in C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\Common.js to a dynamic import() which is available in all CommonJS modules.
    at Common.parseConfig (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\Common.js:317:12)
    at API._startJson (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\API.js:934:25)
    at API.start (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\API.js:329:12)
    at C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\binaries\CLI.js:290:13
    at C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\withoutIndex.js:8:40
    at replenish (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\eachOfLimit.js:81:17)
    at C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\eachOfLimit.js:86:9
    at eachLimit (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\async\forEachLimit.js:47:43)
    at awaitable (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\awaitify.js:13:28)
    at Command.<anonymous> (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\binaries\CLI.js:289:7)
    at Command.listener (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:315:8)
    at Command.emit (node:events:513:28)
    at Command.parseArgs (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:651:12)
    at Command.parse (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:474:21)
    at beginCommandProcessing (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\binaries\CLI.js:147:13)
    at C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\binaries\CLI.js:221:7
    at C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\API.js:181:16
    at C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\Client.js:54:16
    at Timeout._onTimeout (C:\Users\yenil\AppData\Roaming\npm\node_modules\pm2\lib\Client.js:372:9) {
  code: 'ERR_REQUIRE_ESM'
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "ES6",
        "module": "ES6",
        "lib": ["ES6", "DOM"],
        "sourceMap": true,
        "outDir": "./sources",
        "removeComments": true,
        "strict": false,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "resolveJsonModule": true,
        "allowSyntheticDefaultImports": true,
        "moduleResolution": "node"
    }
}
quartz cosmos

the error tells you what you can do

twin tundra
quartz cosmos

try renaming the file to ecosystem.config.cjs

twin tundra
PS C:\Users\yenil\Desktop\new-v14-shield> npm start

> v14-titan-guard-bot@1.0.0 start
> cd sources && pm2-runtime start ecosystem.config.cjs --env production

You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
Error: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at new NodeError (node:internal/errors:399:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
    at defaultResolve (node:internal/modules/esm/resolve:1135:3)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:525:22)
    at importModuleDynamically (node:internal/modules/cjs/loader:1186:29)
    at importModuleDynamicallyWrapper (node:internal/vm/module:429:21)
    at importModuleDynamically (node:internal/vm:106:46)
twin tundra
const bots = [
    {
        name: "Management",
        namespace: "TitanLion",
        script: "main.js",
        watch: true,
        exec_mode: "cluster",
        max_memory_restart: "2G",
        cwd: "file:///C:/Users/yenil/Desktop/new-v14-shield/sources/Bots/Management",
    },
];

module.exports = {
    apps: bots,
};