`getServerSideProps` does not work with Parse server due to `child_process`
See original GitHub issueBug report
Describe the bug
After generating a new Next project, adding Parse, adding a small bit of code to see if the two play together nicely, and running next build
, I get the following error:
$ next build
Creating an optimized production build
Failed to compile.
./node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Can't resolve 'child_process' in '/Users/devanb/Projects/parse-test/node_modules/xmlhttprequest/lib'
> Build error occurred
Error: > Build failed because of webpack errors
at build (/Users/devanb/Projects/parse-test/node_modules/next/dist/build/index.js:13:913)
error Command failed with exit code 1.
I’m not sure exactly what the issue is other than child_process
, unfortunately. In over my head a little 😅
To Reproduce
Full reproduction here: https://github.com/DevanB/next-parse-server
System information
- OS: macOS 10.15.4
- Browser: Safari 13.1
- Version of Next.js: 9.4.0
- Version of Node.js: 12.16.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Module not found: Can't resolve 'fs' in Next.js application
In this module, we have one server-only method and one "shared" method that in theory should work client-side (but as we'll see, theory...
Read more >next js when to use getserversideprops Code Example
getServerSideProps can only be exported from a page. You can't export it from non-page files.
Read more >can't resolve 'fs' import trace for requested module: - You.com
My guess is you are trying to do import {DR_LINK} from "../main"; on client side from a server file. The clue is the...
Read more >Real-time NextJS applications with Parse
Navigate to the index.js file, inside the pages folder. The first thing to be done is to create a function called getServerSideProps. If...
Read more >How to Build Your Own Blog with Next.js and MDX
When I do this, I can conveniently go back to where any issues ... some of them were related to Webpack, modifying your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same here with
next@9.4.1
:This happened after I bumped Next from 9.4.0 to 9.4.1 and also updated a few other deps in one small open-source side project. Here is the commit: https://github.com/kachkaev/video-easter-eggs/commit/d535f5919f82c72d940cf9529804cda935f7ba65
Simply pinning next to
next@9.4.0
inpackage.json
has not helped, so going to investigate further.UPD: Bumping next to 9.4.1-canary.9 does not help either 🤔
UPD2: Probably my issue is in the user land, i.e. in https://github.com/kachkaev/video-easter-eggs/commit/5e3ffaee371c850b73ff81c4774aab9c3784c42c 🤔 It’s a pretty large diff, but most of it is just moving files around. There are no ESLint and TypeScript problems both before and after.
UPD3: @DevanB I resolved the issue for my project 🎉 It had nothing to do with Next.js, purely user land. Roughly speaking, I had:
Here is what I mistakenly did while refactoring
src/ui/MyComponent.tsx
:My expectation was that Next.js would tree-shake the import and thus exclude
doY
while building the client bundle. This did not happen though, so webpack started processingdoY
→execa
→child_process
and failed.Replacing one import statement back with two resolved the issue. Hope that my investigation helps others who face a similar puzzle too 🙂
@kachkaev this makes sense now. Testing locally.
– Update –
This worked! Thanks so much @kachkaev. I understand what’s going on now 😃
I’m closing this report @Timer. Thanks for the help 😄