Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aczekajski opened this issue Feb 28, 2023 · 0 comments
Open

Comments

@aczekajski
Copy link

aczekajski commented Feb 28, 2023

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.
@aczekajski aczekajski changed the title Importing folders starting with dot cause "module not found" error Importing folders starting with dot cause "Cannot find module" error Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant