-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Next.js + Now serverless] Can't resolve 'child_process' in './node_modules/@prisma/photon/runtime' #1226
Comments
Dropping Prisma2 and Photon to preview018 (remove node_modules, package-lock.json, and using absolute version number: 2.0.0-preview018), same error |
Found a similar issue but not sure: vercel/next.js#7334 |
It seems to be solved by not reuse the instance but create a new one every time I need to use it like this |
It blows my mind, I still reuse the instance, but put the file into the project root rather than /utils, still works... Maybe it has something to do with the way I import it, previously, I put it inside |
As long as I import the photon instance from the file it sit directly in, rather than from a index.ts , everything works. |
I think it has to do with how next js is bundling file(I am not familiar with the internals of that library). Next is bundling photon when it is split out in a sperate file. Photon depends on child_process which is a native node js package and it is not available in the browser. I'd suggest opening an issue in the next repo about this. |
Having the same issue when using |
I here 👋 I made a minimal reproduction of the Hope it can help |
@guillaumeLamanda This is expected. The dependencies inside next js getInitalProps are bundled in the client package as the function is executed on the client when you transition a page. Photon is a native nodejs package and uses libraries that are provided by the node standard library like child_process which are not available in the DOM. Segment from next js docs:
This means the getInitalProps function is bundled and webpack can't resolve photon's deps as they are only present in node environment. Next js is working on a new |
I tried |
Thanks @pantharshit00 for this very clear answer. 👌 Indeed, we will need to use I guess this issue can be closed now. |
Closing this now, please feel free to open a new issue if you feel this was not addressed properly |
I had a similar issue. It seems that a generic package import, traverses all files underneath regardless of whether the methods are actually called:
Actually first goes to the root index.js inside the package and calls:
Therefore the error was triggered. Solutions are:
Very simple to fix, but frustrating to find the cause! |
I am using
preview019
with a SQLite dbPhoton sits in a file and being used everywhere
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:However, api is working:
/api/graphql
is working:anything to do with #1021 ?
The text was updated successfully, but these errors were encountered: