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.

resolve does not preserve `require.extensions` list and assumes only ['.js']

See original GitHub issue

Greetings!

Having a situation where we are using tape which does not pass extensions to resolve. Have opened an issue here https://github.com/substack/tape/issues/395

That being said our situation is we use the .es ECMAScript extension with the following:

require.extensions ['.es'] = require.extensions ['.js']

Although we can achieve our needs with the previous tape issue/pr I feel it behoves resolve to use the default require.extensions list provided by node instead of only assuming ['.js'] here https://github.com/browserify/resolve/blob/5f6e682396eca043624d0a13286b9015b1e6cfce/lib/sync.js#L23.

An easy enhancement would be to convert:

var extensions = opts.extensions || ['.js'];

to

var extensions = opts.extensions
  || Object.keys (require.extensions)

Please advise and will have a PR & tests up ASAP as we need this or have to call off using tape and resolve. Can also enhance documentation which should close https://github.com/browserify/resolve/issues/134 which @ljharb, and @call-a3 are working on as well.

Thanks in advance! /cc @brandondees

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
TehShrikecommented, Sep 28, 2017

If this package’s goal is to implement the node.js require.resolve() algorithm, isn’t this something that should be fixed?

Using a truncated default extensions list makes this library default to non-node-like behavior.

Packages like got that require('./package') will break when bundled by bundlers that use node-resolve (which is all bundlers that I’m aware of).

3reactions
ghostcommented, Sep 28, 2017

I think it’s good to not rely too heavily on global runtime vars to configure default values. The whole point of this package instead of using require.resolve() is that you can configure its behavior without mutating the global runtime environment variables.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better way to require.extensions with Node.js - Stack Overflow
One, the node module resolution algorithm is VERY complicated, it has to look at the specified file, if it doesn't exist it looks...
Read more >
Requiring modules in Node.js: Everything you need to know
If a file extension was not specified, the first thing Node will try to resolve is a .js file. If it can't find...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Resolve | webpack
If true , it will not allow extension-less files. So by default require('./foo') works if ./foo has a .js extension, but with this...
Read more >
JavaScript modules - MDN Web Docs
Node.js has had this ability for a long time, and there are a number of JavaScript libraries and frameworks that enable module usage...
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