When "main" matches source and "browser" field set, bundle fails.
See original GitHub issueUsing browserify 14.4.0. masOS Sierra.
Quite a weird repro. When running this command:
browserify module.js -o dist/module.js
And under this set of circumstances:
- The
"main"
field in package.json matches the source file ("module.js"
) - The
"browser"
field is also set (with any value, but in our case"dist/module.js"
)
We get this error when bundling:
Error: module not found: "/<pathroot>/module/module.js" from file /<pathroot>/module/_fake.js
Changing the "main"
field to something else allows browserify to succeed. Removing the "browser"
field also works. Of course these aren’t options for distribution.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Should I use browser field in package.json when authoring a ...
I'm developing a javascript library and I have set 'browser', 'module' and 'main' fields in package.json, each one with a different entry ...
Read more >Resolve | webpack
When enabled, symlinked resources are resolved to their real path, not their symlinked location. Note that this may cause module resolution to fail...
Read more >API - esbuild
To join a set of files together with esbuild, import them all into a single entry point file and bundle just that one...
Read more >Troubleshooting Common Errors - Gatsby
Error : ReferenceError: window is not defined when running gatsby build; Build problems from Field 'browser' doesn't contain a valid alias configuration ...
Read more >Documentation - Module Resolution - TypeScript
Or module paths in the final output may not match their corresponding source file paths at compile time. The TypeScript compiler has a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks like browserify or browser-resolve replaces the path matching the
main
field (eg./xls-populate/lib/XlsxPopulate.js
) by the path in thebrowser
field (browser/xlsx-populateXXX.js
) in some situations. I imagine this is good behaviour for modules insidenode_modules
, but not for local files. https://github.com/browserify/browserify/pull/1834 reproduces the problem.@stevenvachon
When you do
browserify lib
, your browser field mapslib
tolib-es5
. It has to exist before that can be used.I’ll close this since it’s actually the correct behaviour.