question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Next.js + Now serverless] Can't resolve 'child_process' in './node_modules/@prisma/photon/runtime'

See original GitHub issue

I am using preview019 with a SQLite db

Photon sits in a file and being used everywhere

import { Photon } from "@prisma/photon";

export const photon = new Photon();

The initialization caused the problem if I change that to something like export const photon = 123;, then this error goes away.

Maybe I get the initialization wrong? Should not reuse this instance?

The project is next.js v9, api is Now serverless, sits in pages/api

After running next, the 1st render to index works, but go to any page will show the following error: image

However, api is working: /api/graphql is working:

image

anything to do with https://github.com/prisma/prisma2/issues/1021 ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
guillaumeLamandacommented, Jan 17, 2020

I here 👋

I made a minimal reproduction of the child_process error with Next.js.
https://github.com/guillaumeLamanda/nextjs-prisma

Hope it can help

0reactions
kmturleycommented, Jan 3, 2021

I had a similar issue. It seems that a generic package import, traverses all files underneath regardless of whether the methods are actually called:

import { clientSideMethod } from 'mypackage'

Actually first goes to the root index.js inside the package and calls:

export * from './file'; // contains server-side code
export * from './utils'; // contains client-side code only

Therefore the error was triggered. Solutions are:

  1. Use a more specific import import { clientSideMethod } from ‘…/…/node_modules/mypackage/dist/utils’
  2. Dynamically import server-side modules when needed
  3. Split packages or modules into client-side vs server-side

Very simple to fix, but frustrating to find the cause!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error can't resolve 'child_process', how to fix?
create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/Compilation.
Read more >
Can I use Back4App with Next.js? - Google Groups
I want to Use Back4App in my Next.js project, but ... Module not found: Can't resolve 'child_process' in. and if I use. import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found