-
Notifications
You must be signed in to change notification settings - Fork 230
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
Bug: Wrong use of the package.json browser
field
#58
Comments
Debug's setup is actually quite interesting, they don't create and publish a /dist directory, but instead just write their source code in the specific format in /src, removing the need to use rollup in the first place. Most transpilers in webpack (i.e. babel-loader) recommend excluding node_modules from transpilation, as it is assumed that stuff in node_modules is already transpiled, as is the case with debug. Even if that wasn't the case, something like babel should be smart enough not to wrap a file that doesn't need wrapping. |
Found this specification for the |
According to the spec above, the browser field is either:
The As far as I can tell, there is no tool that expects those modules to be umd builds and they will wrap them a second time. The more I read about this, the more I am getting convinced this example project is doing it wrong. |
Yep, sounds like it’s wrong. Who wants to fix it? |
browser
field in this example correct?browser
field
@eventualbuddha and by fix you mean delete the |
Yes, probably. And the part in the README about it. Now here is the weird part. As far as I understand it (haven't been using Rollup in a while), Rollup fully supports the browser field. But somehow the advice here is wrong? This actually conflicts with how Rollup works? But I'm betting that if you would put this example project to the next level and make it more complete you would discover both how the current advice won't work if you follow it and how you should use the browser field to actually do make it work. I think you should give this library a code branch for Node / browsers. Say, read something from env vars on Node or localStorage in the browser. Just a few lines of code. Then use the browser field to specify that on browsers you want to include |
I notice in this example that it is referencing the umd build in the dist folder in the
browser
field of package.json:Thinking of interop with other tools, I wonder whether this is right?
I think Browserify and Webpack both use the
browser
field as having the meaning 'the entry point for this package, for browsers'. But they assume 'normal' cjs code.For example have a look at the
browser
field in the package.json of debug:Notice how they use a file in the src folder here. Both Browserify and Webpack will pick up this file and package / bundle it, wrapping it with a umd wrapper for umd builds.
So I wonder, is it right that the file this project is setting for the
browser
field is a umd build, that already has a umd wrapper? Won't this file end up being wrapped twice?The text was updated successfully, but these errors were encountered: