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

Error in ESM about no extensionless imports does not occur for import with only specifier #52191

Closed
dsherret opened this issue Jan 10, 2023 · 5 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@dsherret
Copy link
Contributor

dsherret commented Jan 10, 2023

Bug Report

Doing import "./other"; will not raise a Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './other.mjs'? error.

🔎 Search Terms

import specifier only side effects

🕗 Version & Regression Information

5.0.0-dev.20230110

⏯ Playground Link

Here's a repo: https://github.com/dsherret/tsc-issues/tree/importOnlySpecifier

💻 Code

{
  "compilerOptions": {
    "moduleResolution": "NodeNext",
    "target": "ESNext",
    "module": "NodeNext",
    "declaration": true,
    "emitDeclarationOnly": true,
    "traceResolution": true
  }
}
// main.mts
import "./other";

// other.mts
export class Test {}

🙁 Actual behavior

Does not error unless I change the import to have a default, namespace, or named import. Output will fail at runtime.

======== Resolving module './other' from 'V:/tsc-issues/main.mts'. ========
Explicitly specified module resolution kind: 'NodeNext'.
Resolving in ESM mode with conditions 'node', 'import', 'types'.
Loading module as file / folder, candidate module location 'V:/tsc-issues/other', target file types: TypeScript, JavaScript, Declaration.
Directory 'V:/tsc-issues/other' does not exist, skipping all lookups in it.
======== Module name './other' was not resolved. ========
File 'V:/tsc-issues/node_modules/typescript/lib/package.json' does not exist.
Found 'package.json' at 'V:/tsc-issues/node_modules/typescript/package.json'.
File 'V:/tsc-issues/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File 'V:/tsc-issues/node_modules/typescript/package.json' exists according to earlier cached lookups.
...etc...

🙂 Expected behavior

Should error because no extension used.

@andrewbranch
Copy link
Member

Side-effect imports like this have never been checked that they resolve whatsoever. @DanielRosenwasser and I briefly discussed whether we could change this, but I don’t know if there was a consensus. It would definitely be a breaking change.

@dsherret
Copy link
Contributor Author

Interesting. Well overall it's not really that big of a deal since people will get an immediate error when running the code and people rarely write these kind of imports.

@andrewbranch
Copy link
Member

Duplicate of #50394

@andrewbranch andrewbranch marked this as a duplicate of #50394 Jan 12, 2023
@dsherret
Copy link
Contributor Author

dsherret commented Jan 12, 2023

Yeah, I should have searched for "side-effects" 😅

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2023
@andrewbranch
Copy link
Member

Added some new discussion in #50394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants