`getServerProps` does not work with native Node.js modules (`fs`, `child_process`...)
See original GitHub issueBug report
Describe the bug
In a getServerProps handler, I would like to use fs. However, I get this error:
ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in '/Users/tim/code/repros/next-child-process/src'
at /Users/tim/code/repros/next-child-process/node_modules/webpack/lib/Compilation.js:925:10
at /Users/tim/code/repros/next-child-process/node_modules/webpack/lib/NormalModuleFactory.js:401:22
at /Users/tim/code/repros/next-child-process/node_modules/webpack/lib/NormalModuleFactory.js:130:21
at /Users/tim/code/repros/next-child-process/node_modules/webpack/lib/NormalModuleFactory.js:224:22
at /Users/tim/code/repros/next-child-process/node_modules/neo-async/async.js:2830:7
at /Users/tim/code/repros/next-child-process/node_modules/neo-async/async.js:6877:13
at /Users/tim/code/repros/next-child-process/node_modules/webpack/lib/NormalModuleFactory.js:214:25
at /Users/tim/code/repros/next-child-process/node_modules/enhanced-resolve/lib/Resolver.js:213:14
at /Users/tim/code/repros/next-child-process/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/tim/code/repros/next-child-process/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
at /Users/tim/code/repros/next-child-process/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
at /Users/tim/code/repros/next-child-process/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/tim/code/repros/next-child-process/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
at /Users/tim/code/repros/next-child-process/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/tim/code/repros/next-child-process/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
at /Users/tim/code/repros/next-child-process/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
I get the same error when importing something from child_process.
To Reproduce
Full reproduction here: https://github.com/timsuchanek/next-child-process
System information
- OS: MacOS, but also Linux in Now
- Version of Next.js: 9.3.5
- Version of Node.js: 12
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
`getServerProps` does not work with native Node.js modules ...
Bug report Describe the bug In a getServerProps handler, I would like to use fs. However, I get this error: ModuleNotFoundError: Module not ......
Read more >Child process | Node.js v19.3.0 Documentation
The node:child_process module provides the ability to spawn subprocesses in a manner that is similar, but not identical, to popen(3) .
Read more >Module not found: Can't resolve 'fs' in Next.js application
Unable to identify what's happening in my next.js app. As fs is a default file system module of nodejs ...
Read more >How To Launch Child Processes in Node.js - DigitalOcean
A key strategy to work around this problem is to launch a child process, or a process created by another process, when faced...
Read more >fs-extra - npm
You don't ever need to include the original fs module again: ... NOTE: You can still use the native Node.js methods.
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 Free
Top 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

You have a typo in your application. It’s not
getServerPropsbutgetServerSideProps.This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.