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
Resolve builtins with --no-browser-field, fixes #1654 #1826
base: master
Are you sure you want to change the base?
Conversation
ab1e4b1
to
a9f2ab1
Compare
a9f2ab1
to
0047b78
Compare
Thanks @goto-bus-stop for the fix. I can confirm that it works and fixes an issue I have. Is it planned to release this fix ? |
Thanks @goto-bus-stop for checking again. Is it ready to merge ? |
We are having this problem too. |
@@ -88,6 +88,10 @@ function Browserify (files, opts) { | |||
self._bresolve = browserField === false | |||
? function (id, opts, cb) { | |||
if (!opts.basedir) opts.basedir = path.dirname(opts.filename) | |||
// Resolve builtin modules. | |||
if (self._mdeps.options.modules[id]) return process.nextTick(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should use resolve’s isCore functionality, i think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb I don't believe so, as custom built-ins can be fed into Browserify, and those won't be picked up by resolve.isCore
. See: https://github.com/browserify/browserify/blob/master/index.js#L551-L553
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If those can override the default ones, then that's a fair point - but then browserify should be using resolve's node-version-specific logic for the defaults, which it doesn't appear to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb Yes, it overrides the defaults, in a way. It's just a direct replacement of built-in resolution. Browserify doesn't use the node-version-specific logic, and that's a separate issue from this one that's worth logging. I'm maintaining a fork right now with this change, and I'd like to be able to depend on the officially published version. Is there anything else holding this up or can it move forward?
Let me know if there's anything I can do to help push a fix for this over the finish line. Use case: I'm using Browserify to custom-tailor third-party modules for use within the Postman Sandbox execution environment (see: https://explore.postman.com/templates/7170/browserify-cdn-modules). Being an Electron app that hosts an even more restricted execution environment, a Browserify CLI call needs to look something like this:
Because of this bug, I get the following error:
This PR fixes the issue for me. Thanks! |
Currently when
browserField: false
or--no-browser-field
is used, builtin modules likepath
andstream
are not resolved correctly. They go through theresolve
module, which simply returns the module name for core modules. Then module-deps tries to read the file namedpath
which doesn't exist (usually).With this patch, builtin modules are checked before calling into the
resolve
module.TODO:
opts.builtins
(currently it will crash like in Unable to resolve stream module with browserField false #1654)