Code Monkey home page Code Monkey logo

Comments (7)

sindresorhus avatar sindresorhus commented on June 8, 2024

Awesome to see this finally being added to core.

from resolve-from.

kevva avatar kevva commented on June 8, 2024

I tried this out using require.resolve with the paths option but couldn't make it work given this structure:

unicorn
    node_modules
        foo.js
    bar
        cat.js
index.js
const path = require('path');

require.resolve('foo', {paths: [path.join(__dirname, 'unicorn', 'bar')]});

I'd expect it to use the regular module resolution and just traverse upwards. Works fine if I run it without the paths option from cat.js.

from resolve-from.

zkochan avatar zkochan commented on June 8, 2024

It should be

const path = require('path');

require.resolve('foo', {
  paths: require.resolve.paths(path.join(__dirname, 'unicorn', 'bar'))
})

from resolve-from.

kevva avatar kevva commented on June 8, 2024

It should work anyway if it follows the usual module resolution which the documentation states it does. Anyway, it doesn't work using your example either.

from resolve-from.

thetutlage avatar thetutlage commented on June 8, 2024

require.resolve doesn't work with custom paths (no idea why), but this module works fine

from resolve-from.

HomyeeKing avatar HomyeeKing commented on June 8, 2024

but it can't work with exports access the esm entry

from resolve-from.

jimmywarting avatar jimmywarting commented on June 8, 2024

Now that NodeJS have paths option built in, then i suppose that there is no point in upgrading this pkg to ESM and we could just deprecate this package and say something like: just use native function, here is how...

from resolve-from.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.