Ran into an issue recently running module-deps, which depends on browser-resolve, where a package which has a dependency with a browser field defined failed to resolve browser assets because the require() call omits the filename extension.
For example, package asap v2.0.3 defines the following browser field in package.json:
And in a module such as promise, you'll find a require() such as:
var asap = require('asap/raw')
This fails to resolve because browser-resolve doesn't seem to handle the missing extension when looking up the file in the browser field. Adding the .js extension to the require() call fixes the issue.
Here's a simple test case calling resolve() directly:
var resolve = require('browser-resolve');
resolve('asap/raw', {}, function (err, path) {
console.log('asap/raw -> ', path);
});
resolve('asap/raw.js', {}, function (err, path) {
console.log('asap/raw.js -> ', path);
});
It'd be great if browser-resolve could resolve the missing extension automatically, otherwise tools like module-deps won't work with packages using shortened filenames.
Ran into an issue recently running
module-deps
, which depends onbrowser-resolve
, where a package which has a dependency with abrowser
field defined failed to resolve browser assets because therequire()
call omits the filename extension.For example, package
asap
v2.0.3 defines the followingbrowser
field inpackage.json
:And in a module such as
promise
, you'll find arequire()
such as:This fails to resolve because
browser-resolve
doesn't seem to handle the missing extension when looking up the file in thebrowser
field. Adding the.js
extension to therequire()
call fixes the issue.Here's a simple test case calling
resolve()
directly:Output:
It'd be great if
browser-resolve
could resolve the missing extension automatically, otherwise tools likemodule-deps
won't work with packages using shortened filenames.