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.

`getServerProps` does not work with native Node.js modules (`fs`, `child_process`...)

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Apr 16, 2020

You have a typo in your application. It’s not getServerProps but getServerSideProps.

0reactions
balazsorban44commented, Jan 30, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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