Skip to content
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] require.resolve changed behavior in node@12, is broken #27794

Closed
RomainMuller opened this issue May 21, 2019 · 3 comments
Closed

[BUG] require.resolve changed behavior in node@12, is broken #27794

RomainMuller opened this issue May 21, 2019 · 3 comments

Comments

@RomainMuller
Copy link

RomainMuller commented May 21, 2019

  • Version: v12.1.0
  • Platform: Darwin f01898256a91 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • Subsystem: require.resolve

Description

I use require.resolve(request, { paths }) to find a file to load relative to a different directory, however this stopped working in node@12, where require.resolve throws Error: Cannot find module ....

Expected Behavior

The require.resolve call returns the absolute path to the requested file, according to the submitted path(s).

Actual Behavior

In node@12, an error is raised.

Steps to reproduce:

/// index.js
const path = require('path');
try {
  const filePath = require.resolve('./target', {
    paths: [path.resolve(__dirname, 'directory')]
  });
  console.log(`Found: ${filePath}`);
} catch (e) {
  console.error('Failed!');
}

/// directory/target.js
console.log('Reached there!');

Result

$ node -v
v12.1.0
$ node index.js
Failed!

$ /usr/local/opt/node@10/bin/node -v
v10.15.3
$ /usr/local/opt/node@10/bin/node index.js
Found: /tmp/repro/directory/target.js

$ /usr/local/opt/node@8/bin/node -v
v8.16.0
$ /usr/local/opt/node@8/bin/node index.js
Found: /tmp/repro/directory/target.js
@RomainMuller RomainMuller changed the title require.resolve does not work in node@12 as it did in previous versions [BUG] require.resolve changed behavior in node@12, is broken May 21, 2019
@mscdex
Copy link
Contributor

mscdex commented May 21, 2019

I believe this is already fixed by #27598, which should be available in the upcoming node v12.3.0.

@cjihrig
Copy link
Contributor

cjihrig commented May 21, 2019

I just verified locally that this is fixed on master, and the fix will go out in 12.3.0 as previously mentioned. I'm going to close this issue out.

@cjihrig cjihrig closed this as completed May 21, 2019
@RomainMuller
Copy link
Author

Whee! Thank you guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants