Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.59k stars 2.62k forks source link

use pm2 start index.ts occur Error #5784

Open painstgithub opened 8 months ago

painstgithub commented 8 months ago

os:windows server 2022 use "node_modules/.bin/ts-node index.ts " can start express service use "pm2 start index.ts --interpreter node_modules/.bin/ts-node " can't start express service pm2 log as below:

0|index | import express from 'express'; 0|index | ^^^^^^ 0|index | 0|index | SyntaxError: Cannot use import statement outside a module 0|index | at internalCompileFunction (node:internal/vm:73:18) 0|index | at wrapSafe (node:internal/modules/cjs/loader:1178:20) 0|index | at Module._compile (node:internal/modules/cjs/loader:1220:27) 0|index | at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) 0|index | at Module.load (node:internal/modules/cjs/loader:1119:32) 0|index | at Module._load (node:internal/modules/cjs/loader:960:12)

tsconfig.json as below: { "compilerOptions": { "module": "CommonJS", "esModuleInterop": true, "target": "ES2016", /"target": "es6",/ "rootDir": "./", "outDir": "./build", "strict": true },

} image

ultimate-tester commented 8 months ago

This is not related to PM2. You need to set your package type to module: https://nodejs.org/api/packages.html#type