-
Notifications
You must be signed in to change notification settings - Fork 104
Description
The tsconfig-paths package is resolving to a local JSON file rather than the expected JavaScript file from a node module binary. This behaviour is causing unexpected issues when attempting to resolve modules in a specific use case.
Steps to Reproduce
Clone the repository: https://github.com/jaysoo/nx-tsconfig-path-issue
- Navigate to the project directory and install dependencies:
npm install - Run the
main.jsscript:node main.js
The script is expected to resolve to a.jsfile within thenode_modules/.bindirectory. However, it incorrectly resolves to a localnx.jsonfile instead.
Additionally we have afoo.jsonbeing resolved (To ensure that it was not the nx package which is causing the resolution issue)
Expected Behavior
The require.resolve function should resolve to the .js file specified in the node_modules/nx/bin/nx.js directory
Actual Behavior
The require.resolve function resolves to a local nx.json file.
Potential Cause and Solution
The issue seems to stem from the matchFromAbsolutePaths function in the tsconfig-paths package, specifically this block of code which uses require.extensions to include .json files in the resolution process.
interface RequireExtensions extends Dict<(m: Module, filename: string) => any> {
'.js': (m: Module, filename: string) => any;
'.json': (m: Module, filename: string) => any;
'.node': (m: Module, filename: string) => any;
}Is there a way to exclude .json files from this resolution process, or to otherwise prioritize .js files from node_modules/{package}/bin/... over local .json files? This would ensure that the require.resolve function behaves as expected and resolves to the correct module.