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

Add Node DNS as a Webpack mock - PR Linked #6277

Closed
Downchuck opened this issue Jan 25, 2019 · 5 comments
Closed

Add Node DNS as a Webpack mock - PR Linked #6277

Downchuck opened this issue Jan 25, 2019 · 5 comments

Comments

@Downchuck
Copy link
Contributor

Presently CRA works quite well for isomorphic web applications: I've only hit one strong issue -- node built-ins as required by submodules. So when I hit: "Module not found: Can't resolve 'dns'" with my yarn start, I was unable to work around it, short of manually editing a node module (a pain).

Several libraries have worked to remove dns from their require statements. This issue bubbled from node-postgres, which has a direct require('dns') statement that I've had to comment out. With that done, life just works, for a rather large and complicated, multiple component application.

Unfortunately, I've not found another route.

I attempted to add a stub for dns in package.json, but as "pg" is included from the sub-project, I was unable to work-around the issue. As I'm using serve and build, not test, I don't have Jest mocks to fall back on.

I am doing all I can not to run an eject, as I'd like to stay simple and with the mainline of CRA.

So with all of that said, I'm looking/asking if there is a method for accommodating the peculiar use case of dependencies that have calls to node built-ins, such that they do not break the build.

Obviously I am not asking that we actually make them work -- once the build runs I have no issue mocking those libraries to take different routes.

@Downchuck
Copy link
Contributor Author

Here's an example of a work-around that didn't work for me, in node-postgres, because node-postgres itself is included from a submodule: skeggse/isemail#26 (comment)

@heyimalex
Copy link
Contributor

Maybe we should just add dns to the stubbed node builtins here.

@Downchuck
Copy link
Contributor Author

@heyimalex That seems likely to fix the issue I'm hitting. My active thread for node-postgres brianc/node-postgres#1822 is not likely to result in a change in their codebase.

It's also a little strange for them to need to move a require statement down into a try catch block. Once the stub is in, I believe I can easily just mock any calls that libraries are using. I'll go ahead and submit a PR.

@Downchuck
Copy link
Contributor Author

PR seems to have stalled on some unrelated Travis CI things.

@Downchuck Downchuck changed the title Surviving webpack with node built-ins Add Node DNS as a Webpack mock - PR Linked Feb 5, 2019
@Downchuck
Copy link
Contributor Author

@mrmckeb I'm getting stuck on the build - is this directly related to mocking DNS or just a temporary issue with the CI?

@lock lock bot locked and limited conversation to collaborators Feb 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants