-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
import from "."
doesn't reference folder if folder and file have same name
#45563
Comments
Your minimal repro doesnβt seem to be a reproβit doesnβt have any imports from |
whoops, I hit undo one too many times before committing. Fixed, sorry. Issue is in |
Thanks! Now if you donβt mind, can you restate your actual behavior and expected behavior in terms of the file names and identifiers used in that repro? I had a little trouble following your hypothetical example. |
Sure.
I would expect |
Also I just tested this in node using And I learned that es6 modules oddly don't officially support directory imports... |
So in Node's official ESM support yes you can't import directories, you have to import the file you want directly or use a package and Technically TypeScript doesn't support Node's ESM behaviour at all atm. Although the issue you're getting is a TypeScript specific issue as it only recognizes CommonJS style imports atm. So yeah Proper ESM support with the same behaviour as Node's esm mode is expected in the next major version of TypeScript (but it could be delayed as its a big job). In this case it should be an error as per Node's official ESM resolution. |
Bug Report
π Search Terms
import folder file refactor
π Version & Regression Information
4.4.0-insiders.20210805, next, and the 4.3.x branch
β― Playground Link
Can't reproduce in playground as it has to do with multiple files and imports
π» Code
This has to do with file imports, so I made a minimal repro:
https://github.com/MarkKahn/ts-import-refactor-bug.git
π Actual behavior
I was refactoring a file,
module.ts
into a directory,module
. I createdmodule/index.ts
, and inmodule/submodule.ts
I had written:import { otherSubModule } from '.'
TS threw an error saying
Module '"."' has no exported member 'otherSubModule'.ts(2305)
After some banging my head on the wall I figured out that
from '.'
wasn't referencing./index.ts
, but instead was referencing../module.ts
π Expected behavior
import from '.'
should reference the current folder, always. This is likely only a bug that would be triggered when refactoring code as I can't think of a use case for a file and folder to have the same name and be a valid structure.The text was updated successfully, but these errors were encountered: