dividab / tsconfig-paths

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

Resolve to JSON file instead of node module #108

Open SamyPesse opened 4 years ago

SamyPesse commented 4 years ago

When using tsconfig-paths with ts-node, it conflicts a require of a node modules having the same name as a JSON file in the root folder.

Basically here is a tree to represent the issue:

node_modules/
  firebase/
  @firebase/testing/
     index.js  => contains a "require('firebase')"
firebase.json
package.json
script.ts => import "@firebase/testing"

Running script.ts with ts-node/tsconfig-paths fails because the require('firebase') returns the content of the firebase.json.

Workaround: In the paths typescript config, I've added:

"paths": {
  "firebase": ["node_modules/firebase"]
}
adamvictorclever commented 4 years ago

I ran into this same issue today and was quite confused what was happening! It would be great if this could be fixed to prevent others from spending time debugging this weirdness.