-
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
internal/node/node_loader.js does not support NODE_PATH #304
Comments
I've gone a bit deeper and discovered that by using I've scripted a quick npm This way whenever the package manager is run to alter the "node_modules" directory it would also keep the BUILD file updated and you can access direct dependencies using your nodejs_binary's I am actually trying down this path, it could even make the node_binary's attribute "node_modules" unnecessary in my case. I'll keep you updated as I discover more. |
I can confirm that by automatically listing all node_modules as I had faced two issues during this process (let me know if you prefer to discuss them in a new issue):
diff -r rules_nodejs/internal/node/node.bzl rules_nodejs_2/internal/node/node.bzl
35c35
< mapping = r"{module_name: /^%s\b$/, module_root: '%s'}" % (escaped, mr)
---
> mapping = r"{module_name: /^%s$/, module_root: '%s'}" % (escaped, mr) |
@lexor90 Thanks for the detailed write up on your issue and work-around. We're also working on fine grained npm deps with #302 although it wouldn't apply to your case with checked-in node_modules. #302 creates fine grained npm deps when using The two issues you found look valid. I haven't run into any cases where the patched node resolver is needed on a spawned node process but your observation makes sense. And the second issue looks like a problem with resolveToModuleRoot() in |
Hey there, thanks for the interest. Regarding #302 I'm following the discussion and the design process, I agree it's definitely useful to track down single dependencies (we made some custom tooling to track them, but it looks weird as it works with genrules). I made some tests on our internal artifacts, produced in conjunction with Also, it makes sense to me a vision where the BUILD file replaces the Let me know if I can help with it. I'm going to open two tickets to track down the issues above and provide a use case for the 1st issue, closing this. |
@gregmagolan maybe you want to keep this open to track down the |
Hello there,
I'm facing issues loading modules from a node_modules directory which does not sit on the project root. I've done a bit of inspection of the new node_loader introduced by #253 and it seems it sets the NODE_MODULES_ROOT always as
workspace_name/node_modules
, ignoring any NODE_PATH.In particular, with older releases (0.10.1 seems to be the latest working - after that #253 was merged) I was able to keep node_modules in
//third_party/nodejs/yarnpkg.org/node_modules/
(checked in the repo).I notice 2 issues:
filegroup(name="node_modules",...)
's "srcs" is not a label it doesn't work (nothing goes into runtimes using, say, a "glob", while referencing it through a sub-//third_party
BUILD file - which includes proper license requirements - works again. I guess this might be forced by bazel itself, as third_party is special. [N.B. this was also happening with previous releases of bazel and rules_nodejs]. Not a drama, by the way.I'm a bit confused about the intended bahaviour, what if my rule is this:
Where node_modules is
And
third_party/nodejs/yarnpkg.org/node_modules:node_modules
is(this is why having fine-grained or automated tools like
gazelle
to do this on each single packages would be awesome).By using
NODE_PATH=/<absolute-path>/lib:/<absolute-path>/third_party/nodejs/yarnpkg.org/node_modules/ bazel run //product/nodejs/frontend:frontend
I was fine. Now I cannot satisfy both requires (I cannot anymore "require("lodash"); require("framework"); // /lib/framework
and I cannot even make it work by usingrequire("lib/framework")
.), I tried patching the resolver, supportingNODE_PATH
and trying toresolveRunfiles()
on every single path, but I could not come up with something working: when the application spawns childrens the require start failing again, the initial checks executed by "node_loader.js" are fine, then fails with a node runtime error trying to import "framework" which initializes the application. Maybe we could pass somehow the NODE_PATH to the actual binary execution (I think somewhere in the bash script)? Or what should be changed in the current setup to work with the new loader?Tests executed using bazel
0.16.0
and0.16.1
and rules_node, from0.12.2
down to0.10.1
on a MacOS 10.14-beta and Ubuntu LTS.P.S. I'd also love to know what you guys do to keep trace of lib requirements using the current "global node_modules", to avoid keeping unreferenced or outdated dependencies, and how do you manage vendoring in a proper way, given issues that arise with "node-gyp" for native modules, which only compiles on the current architecture. We currently only execute "npm install" on a target machine having the same OS/Setup like production environments and then check-in only these outputs. Of course locally it's a mess if you try to require native modules, which have been built on a remote architecture, and it would be nice to being able to compile native modules with bazel itself from sources. Maybe RBE will be helpful here to always run tests on the same architecture as the checked-in modules regardless of the dev machine.
The text was updated successfully, but these errors were encountered: