-
Notifications
You must be signed in to change notification settings - Fork 522
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
Forked processes are unable to resolve node_modules/ #312
Comments
@gregmagolan and I discussed how doing as suggested in #315 would fix this. We could change our approach to have an action that lays out a node_modules tree with a composition of node_modules from the local repository, remote repositories, and JS outputs of rules. Then at runtime we'd only need to point nodejs at this output directory and could use vanilla nodejs resolution. It would move the complexity from runtime to build-time. I think we'll do an investigation of this once we're done landing the fine-grained node modules everywhere and confirm the performance improvements. |
@alexeagle I did something very similarly internally at work but the performance was terrible since I needed to construct the node_modules layout for every I'd be good to see the custom |
@nimerritt could you elaborate on your workaround regarding using module_mapping? |
For anyone else coming across this, I have a workaround. You can use the Our BUILD file ended up looking something like this:
And then when you want to actually fork, you can do something like:
|
Thanks for documenting that @lewish - this is a nice workaround |
Looks like the
|
Actually, this is not an enhancement I think. Forking is a must-have feature in the nodejs world. |
I do think this feature is required, even to run terser in parallel #833, we have to hack to get around this, therefore fixing it would it much easier @alexeagle Suggested having a "slow" version of @filipesilva Suggested the use of While I like the second option a lot I think we can do better to come up with a method that is no slower than the current implementation and without having to change current worker scripts. However it may be a reasonable solution for now since |
@Toxicable will the forked process be able to find the patch.js file in second option because since the forked process can have different CWD rather than its parent's CWD? |
@thesayyn not if we reference it as a relative script, but if we placed it in a node_modules, then nodejs goes through all parent dirs looking for node_modules |
I this case it's not a elegant solution I think. Custom loaders and likewise solutions can come up with a problem easily in the future. The solution should output artifacts that can be run outside of the bazel world. I guess I'll +1 the first solution which we put the all artifacts into node_modules on build time. |
@thesayyn you can +1 the new //internal/linker which puts all the artifacts into node_modules It doesn't do it at build time though - that's too slow as observed earlier. Instead we sneakily do it as a separate program just before launching node. I think we can close this now that the linker is in use. We'll keep #315 to track the work of actually moving all bazel node programs away from the custom resolver - but if you want to fork processes you now can. @Toxicable let's work on getting your terser worker threads landed in //packages/terser now? let me know how I can help |
Closes bazel-contrib#312 PiperOrigin-RevId: 218547300
Closes bazel-contrib#312 PiperOrigin-RevId: 218547300
As reported in #304
Currently, if a process spawns other processes these don't get the patched
node_loader.js
. It means that every time you fork a process it will start failing because it cannot resolve anyrequire('xyz')
.An example use case might be a web server where you
cluster
ize the process sharing a single port (the master waits for connections, workers do the request handling - in node this is so easy that it's very common). This can be worked around starting node in a single process (no master-worker architecture) and then use some orchestrator to have multiple copies of the process (but of course you need an external load balancer, which might not be an option for everyone).Another valid example might be a process willing to spawn separated processes for heavy data calculations to avoid blocking the main thread and have the master to respond to RPC calls.
The text was updated successfully, but these errors were encountered: