question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When "main" matches source and "browser" field set, bundle fails.

See original GitHub issue

Using 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
goto-bus-stopcommented, May 15, 2018

It looks like browserify or browser-resolve replaces the path matching the main field (eg. /xls-populate/lib/XlsxPopulate.js) by the path in the browser field (browser/xlsx-populateXXX.js) in some situations. I imagine this is good behaviour for modules inside node_modules, but not for local files. https://github.com/browserify/browserify/pull/1834 reproduces the problem.

0reactions
goto-bus-stopcommented, Jul 22, 2019

@stevenvachon

Both of my files are CommonJS modules, but I still experience this error.

When you do browserify lib, your browser field maps lib to lib-es5. It has to exist before that can be used.

I’ll close this since it’s actually the correct behaviour.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found