resolve icon indicating copy to clipboard operation
resolve copied to clipboard

Unable to resolve a package by its own name

Open fasttime opened this issue 1 year ago • 2 comments

This is a reminder that package self-referencing is not supported at this time.

package.json

{
  "name": "my-package",
  "main": "./index.js",
  "dependencies": {
    "resolve": "*"
  },
  "exports": {
    ".": "./index.js"
  }
}

index.js

const resolve = require('resolve/sync');

// prints full path of index.js
console.log(`require.resolve: ${require.resolve('my-package')}`);

// throws MODULE_NOT_FOUND
console.log(`resolve: ${resolve('my-package')}`);

DEMO LINK


I imagine this must be a known limitation, since other features linked to module resolution in Node like package imports are not supported either. I'm reporting this here anyway because I could not find a reference to this in the documentation or in any of the other issues.

fasttime avatar Aug 14 '22 16:08 fasttime

Yes, the reminder isn’t necessary - we don’t yet support “exports” or any of the features that landed with it, including self-referencing.

ljharb avatar Aug 14 '22 19:08 ljharb

¿Alternatives? :')

alejooroncoy avatar Oct 12 '22 23:10 alejooroncoy