pm2
pm2 copied to clipboard
PM2 API connection error in Next.js 14: 'Module not found: Can't resolve term.js
What's going wrong?
I was trying to utilize the pm2 API for a Next.js project, but when I imported it into the API directory and connected it, an exception was thrown: "Module not found: Can't resolve 'term.js'."
How could we reproduce this issue?
Create a nextjs 14 app using create-next-app and install pm2. After installation inside /app/api/test/route.ts write a simple route as below.
import { NextResponse } from "next/server";
import pm2 from "pm2";
export async function GET(request: Request) {
pm2.connect((err) => console.log(err));
return NextResponse.json({});
}
Traceback
▲ Next.js 14.2.4
- Local: http://localhost:3000
✓ Starting...
✓ Ready in 4.3s
○ Compiling /api/process/all ...
⨯ ./node_modules/blessed/lib/widgets/terminal.js:93:1
Module not found: Can't resolve 'term.js'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/blessed/lib/widgets/ sync ^\.\/.*$
./node_modules/blessed/lib/widget.js
./node_modules/blessed/lib/blessed.js
./node_modules/pm2/lib/API/Dashboard.js
./node_modules/pm2/lib/API/Extra.js
./node_modules/pm2/lib/API.js
./node_modules/pm2/index.js
./app/api/process/all/route.ts
Supporting information
OS: windows 10
NodeJS: v20.11.1
yarn: 1.22.22
next: 14.2.4
pm2: ^5.4.0
typescript: ^5
Same issue. Have you ever found a solution to this?