Cannot read property 'equal' of undefined
Closed this issue · 7 comments
Hello, nanobus
doesn't work in browser. Why do you use Node API?
var assert = require('assert');
will break code for browsers.
The same for nanotiming
. You assure that lib will work in browsers but it's wrong (from nanotiming
README: Works both in the browser and Node)
nanoscheduler
has nanoassert
as dependency and as I understand for browsers you replace node
's assert
with your nanoassert
using package.json
browser field:
"browser": {
"assert": "nanoassert"
},
Am I right?
Thanks
Can you share a bit more about your setup? Webpack and browserify should automatically replace the assert module with nanoassert. (Even if they don't, they ship with a version of the assert
module that works in the browser, so it should still be fine.)
I use rollup
for bundling. Is any ways to achieve this behaviour using rollup? or should I switch to browserify?
hmm, I thought rollup-plugin-node-resolve would respect the browser field when setting the browser: true
option, but it looks like it's not working correctly.
You can get the same browser versions of core modules as browserify uses with the node-builtins plugin.
@goto-bus-stop thank you. I get it to work after adding rollup-plugin-node-builtins
and rollup-plugin-node-globals
into my rollup.config.js
. I think we can close it. I don't know, maybe it will be good to have some info about rollup in readme. What do you think?
@ok2ju hmmm, it sounds like this isn't so much nanobus
specific, as it's a an issue with rollup
. I think this issue in itself might be enough to help point people in the right way.
it's a an issue with rollup
Ran into this issue and would like to leave a comment in the hope of this being reconsidered: I would not consider this an issue with Rollup. I would consider this an issue with nanobus relying on non-standard magic performed by two popular bundlers.
The fact that Rollup doesn't implement this extra non-standard magic is not a Rollup bug; this magic is an optional QoL feature that the webpack/browserify devs have chosen to implement, but it doesn't seem reasonable to expect every library in the world to follow suit for compat.
Just my 2c.
If my comment from back then is still accurate:
I thought rollup-plugin-node-resolve would respect the browser field when setting the browser: true option, but it looks like it's not working correctly.
then it is/was a bug in the node-resolve plugin. It claims to support the "browser"
field, and this package uses it in probably the most basic way possible.
As for using assert
at all…this is a Node module that assumes it is bundled with a Node module bundler. Providing shims for core modules is not an optional or qol feature for a node module bundler, but a hard requirement, since node modules universally assume that they can require core modules. Rollup is not a Node module bundler, but it can behave like one with plugins.