Skip to content
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

Can't resolve fs module when using with server-side rendering and defaults #136

Closed
2 tasks done
OKNoah opened this issue Mar 17, 2021 · 7 comments · Fixed by #142
Closed
2 tasks done

Can't resolve fs module when using with server-side rendering and defaults #136

OKNoah opened this issue Mar 17, 2021 · 7 comments · Fixed by #142
Assignees

Comments

@OKNoah
Copy link

OKNoah commented Mar 17, 2021

  • 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:

  1. Use next@9, @expo/next-adapter and the latest react-native-dotenv with default settings.
  2. Run dev mode via next.
  3. 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
@github-actions
Copy link

Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/136

@goatandsheep
Copy link
Owner

goatandsheep commented Mar 17, 2021

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 😓 https://www.npmjs.com/package/react-native-clean-project

@OKNoah
Copy link
Author

OKNoah commented Mar 17, 2021

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.

@goatandsheep
Copy link
Owner

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'

@OKNoah
Copy link
Author

OKNoah commented Mar 17, 2021

@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.

@goatandsheep
Copy link
Owner

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.

@OKNoah
Copy link
Author

OKNoah commented Mar 17, 2021

Good idea.

goatandsheep added a commit that referenced this issue Apr 6, 2021
goatandsheep added a commit that referenced this issue Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants