Importing folders starting with dot cause "Cannot find module" error
aczekajski opened this issue · comments
Arkadiusz Czekajski commented
I have a folder .foo
directly in project root with some modules in it.
Somewhere else in the project I do a non-relative import:
import { baz } from '.foo/bar';
In tsconfig I have set "baseUrl": "."
, there are no paths
and I added tsconfig-paths:
"ts-node": {
"files": true,
"require": ["tsconfig-paths/register"],
}
The tsc
works fine, vscode can see that the import is correct (it was actually the autoimport in vscode that created the import). But when running with ts-node
it fails with error:
Error: Cannot find module '.foo/bar'
Expected behavior:
ts-node
with tsconfig-paths
registered should be able to import the module using non-relative import just as any other folder without a dot.
Additional info:
- trying to explicitely add
".foo/*": [ "./.foo/*" ]
topaths
does not help - importing other folders as non-relative (ie.
import { sth } from 'sth'
) works just fine with this config. - adding
"@foo/*": [ "./.foo/*" ]
topaths
and changing the import toimport { baz } from '@foo/bar'
works ok, so it's not a problem with what the paths are mapped to. It seems to be a problem with the left-hand side of mapping.