dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Importing folders starting with dot cause "Cannot find module" error

aczekajski opened this issue · comments

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/*" ] to paths does not help
  • importing other folders as non-relative (ie. import { sth } from 'sth') works just fine with this config.
  • adding "@foo/*": [ "./.foo/*" ] to paths and changing the import to import { 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.