Skip to content Skip to sidebar Skip to footer

NPM Package.json Base / Root Property?

Is there a package.json property that can be used to specify the root folder that module resolution should start? For example suppose we have an install in node_modules/mypackage/s

Solution 1:

ECMAScript modules support an experimental exports property in package.json. You can try something like:

{
  "exports": {
    "./": "./src/"
  }
}

Then imports like:

import file1Module from 'mypackage/file1'

Should load from ./node_modules/mypackage/src/file1.js. If its not possible to alias the root you would have to do:

{
  "exports": {
    "./file1": "./src/file1.js"
  }
}

For every module or directory you wanted to alias.

As noted on your GitHub issue.


Post a Comment for "NPM Package.json Base / Root Property?"