With-Plasmic-Prepass: Not killing dev server process / port on build error

What are you trying to do?

We’re using the app router and the @plasmicapp/nextjs-app-router package.

When running following yarn script with-plasmic-prepass -v=true -- next build to extract query data for prerendering - the dev server get’s started correctly, but when the next build commandProcess exits during Linting and checking validity of types due to a typescript / import error, the with-plasmic-prepass scripts tries to kill the dev server, but somehow it fails.

Example when using a non-existent import in the app:

Plasmic: starting prepass dev server at http://localhost:56284 via "npm run dev"...

> website@0.1.0 dev
> cross-env NODE_ENV=development next dev


   ▲ Next.js 15.1.6

   - Local:        http://localhost:56284
   - Network:      http://172.31.112.1:56284
   - Environments: .env.local, .env
   - Experiments (use with caution):
     · staleTimes


 ✓ Starting...

Plasmic: Dev server started
 ✓ Ready in 3.9s

Plasmic: Running command: next build
Plasmic: Command running with pid 32392
   ▲ Next.js 15.1.6
   - Environments: .env.local, .env
   - Experiments (use with caution):
     · staleTimes

   Creating an optimized production build ...
Failed to compile.

./src/app/[locale]/[[...catchall]]/page.tsx
Module not found: Can't resolve '@/utils/extract-data'

https://nextjs.org/docs/messages/module-not-found


> Build failed because of webpack errors
Plasmic: Command finished; killing prepass dev server...
Plasmic: Failed to kill dev server: Error: spawn C:\dev\website\node_modules\@plasmicapp\nextjs-app-router\dist\fastlist.exe ENOENT

Therefore the dev server port is still used, some node.exe processes are still left running.

I couldn’t fork the relevant project to try changes locally and create a PR (cannot build and reference the project or I don’t know correctly how to do so).

Hello @michaelb, thank you for the detailed bug report. I see that you are using Windows. Do other Windows users in your team also get the same error?

We use the fkill library to kill dev process, and possibly it fails to kill the process on Windows. Can you help us confirm that?

  1. Run npm run dev on any Nextjs project. Lets assume that it starts the app on port 3000
  2. Install fkill in the project.
  3. Create a file called test.js. Copy the following code snippet:
(async () => {
    const fkill = (await import('fkill')).default;
  
    fkill(':3000', { force: true })
      .then(() => console.log('Process on port 3000 killed'))
      .catch((err) => console.error(`Failed to kill process: ${err}`));
  })();
  1. Run the script on the terminal node ./test.js
  2. Check if it kills port 3000 or not.

Thanks for guidance.

Yup, we’re running on Windows (Powershell) and other team members get the same error.

I ran your steps. When starting dev server alone and trying to kill via fkill seems to work.

❯ node .\test.js          
Process on port 3000 killed

Running them with with-plasmic-prepass starts dev server and then yarn build throws error above when there’s a build error → killing dev server afterwards (when build command exits) fails

Thank you for confirming. Just for clarity, after fkill fails to kill the dev server during with-plasmic-prepass, did you try running the test.js script, replacing 3000 with the dev server port that failed to kill? You can find what port it is running on, by looking at the logs - E.g. in the logs you shared, the port is 56284 (but it will be different every time you run it):

Plasmic: starting prepass dev server at http://localhost:56284 via "npm run dev"...

Also, can you try test.js script with fkill version 8.1.1?

npm i fkill@8.1.1

Ah thanks, I forgot testing that case.

So after running with-plasmic-prepass and trying to kill the hanging dev server by running node .\test.js with fkill@8.1.1 the process gets killed and the port has been released again.

Process on port 65009 killed

Thank you for your cooperation. Unfortunately, I am unable to reproduce the issue on my end. In the error message:

Failed to kill dev server: Error: spawn C:\dev\website\node_modules\@plasmicapp\nextjs-app-router\dist\fastlist.exe ENOENT

It says that it was unable to spawn a fastlist.exe file. The path is supposed to be C:\dev\website\node_modules\process-exists\node_modules\ps-list\fastlist.exe instead!
Can you check that your node_modules are installed correctly and the process-exists package exists in the node_modules?

I do have node_modules\process-exists and another one node_modules\ps-list\fastlist.exe
But the latter is not contained in the first one.

For clarity: We’re using yarn v4.5.0 instead of npm.

Hey @michaelb , could you upgrade to the latest version of loader-nextjs and give it another try on Windows? We’ve recently switched to a different library for shutting down the dev server.

Thanks for the update! That works perfectly :slightly_smiling_face:

1 Like