Can't resolve fs module when using with server-side rendering and defaults
OKNoah opened this issue · 7 comments
- Tried the troubleshooting Wiki
- Followed the migration Wiki
Describe the bug
Next gives me the error that it can't resolve the modules fs
when I use a moduleName
other than react-native-dotenv
. I tried fixing another bug by using the defaults (@env
), but that seemed to produced this problem. This may be unique to next@9
or whatever webpack it uses.
For the curious, I seem to have eliminated my original bug but updating things blindly, but it was a case of react-native-dotenv
returning undefined
for variables, depending on whether I did a console log in a particular place. That "solution" seemed to be machine-specific, as another user resolved still faced it but resolved it by removing some whitespace.
To Reproduce
Steps to reproduce the behavior:
- Use
next@9
,@expo/next-adapter
and the latestreact-native-dotenv
with default settings. - Run dev mode via
next
. - Get error in terminal (server-side).
Expected behavior
The server-side rendering shouldn't fail with an error about dotenv
not being able to resolve fs
.
Desktop (please complete the following information):
- OS: macOS
- Browser: Terminal
- Version 11.2.3
Hey, thank you for opening this issue!
Yeah that should not be happening especially since the package is installed as a devDependency, but you said you followed the troubleshooting guide.
Also the whitespace seems to be a caching issue. I'm going to be updating the readme next week with a recommended package to help with the caching issue. It's coming up in every other ticket
Yeah that should not be happening especially since the package is installed as a devDependency, but you said you followed the troubleshooting guide.
This is in dev mode, which I should have emphasized more. Perhaps one solution would be to somehow mix solutions, but thought it was interesting how the moduleName made a difference.
Oh I know now what happened!! If you change moduleName
to babaganoush
, you need to change your inputs too like so:
import { ENV_VAR } from 'babaganoush'
@goatandsheep yep, did that. I was able to find and replace @env
after to successfully undo the change, so that suggests I didn't miss anything.
Well, thanks so much for the submission!
I'm going to leave this open because this is valid. I might just recommend people set their moduleName to react-native-dotenv
for nextjs. I think this is an edge case that would take more effort than it's probably worth to fix.
If you have suggestions, feel free to comment below or open a PR.
Good idea.