dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

Forwarding an absolute path to _resolveFilename skips package exports checks #266

Closed martinjlowm closed 5 months ago

martinjlowm commented 5 months ago

Trying to import a package that has entries for CommonJS and ESM fails to evaluate the exports field. An easy regression is to evaluate this against @eslint/eslintrc (which was where I noticed the behavior):

(NODE_OPTIONS="-r tsconfig-paths/register"; node -e "console.log(require.resolve('@eslint/eslintrc/universal'))")

The output is /<project>/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/universal.js but should be /<project>/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs

My suggestion is to terminate and hit the original implementation early if the resolved path is in node_modules.

martinjlowm commented 5 months ago

Never mind - turns out I had a paths-configuration pointing resolutions towards node_modules/* 🤷