Provide an option to define in what directory the module will be resolved.


(Joan Peralta) #1

Hi everybody, i’m Joan Peralta, this is my first idea in the NPM community, I hope everybody have a good day.

The problem:

  • I have 2 projects in my application structure, I have a core library (@components) that is made in typescript and then compiled to plain-javascript in the build directory that exports an object CustomTable in the file build/CustomTable.js
  • In my another project that depends of the package @components, included using npm link, I had to specify the folder build when i’m trying to import the component CustomTable as following:

import CustomTable from '@myOrganization/components/build/CustomTable';

The possible solution:
Provide an option in the package.json that defines in what directory the module should be resolved, something like:

{ "name": "@myOrganization/components", "version": "0.0.1", "resolveModuleFrom": "./build", "depedencies": ... }

Then when I can use:

import CustomTable from '@myOrganization/components/CustomTable';

And the file CustomTable.js should be resolved in the build folder.

I hope to read your answers.


(Mark) #2

Side note: there is a package-name-maps proposal to use packages based on a custom mapping. It doesnt specifically cover your use case yet, but if the node team implements it, it may be worth adding your use case as a feature there.