Reputation: 105
I have a folder structure like so:
projectRoot
├── src
│ ├── app.ts
├── node_modules
│ └── foo
│ └── src
| |__ foo
| |__ foo-code.ts
And in app.ts I have an import which I was to look like this:
import fooCode from "foo/foo-code";
As far as I understand from the docs, I should be able to achieve this with something like the following tsconfig:
{
"compilerOptions": {
"baseUrl": "."
},
"paths": {
"*": [
"src/*"
],
"foo/*": [
"node_modules/foo/src/foo/*"
]
}
}
However upon compiling I get an error
error TS2307: Cannot find module 'foo/foo-code'
Any ideas on what I'm doing wrong?
Thanks
Upvotes: 0
Views: 455
Reputation: 105
Okay turns out there were a few issues:
1) I was running tsc with a file specified, which according to the docs, means tsconfig is ignored!
2) Paths should have been inside compilerOptions
3) A better path resolution strategy would have been
"paths": {
"*": [
"*",
"src/*",
"node_modules/foo/src/*"
]
}
Upvotes: 1