Skip to content

Typescript compiler doesn't fail when importing {} from a module that doesn't exist #20576

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

Closed
ramaghanta opened this issue Dec 8, 2017 · 3 comments
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@ramaghanta
Copy link

TypeScript Version: 2.6.2 (tried with 2.7.0-dev.20171208)

Code

import {} from 'nothing';

Expected behavior:
tsc should fail with an error "Cannot find module 'nothing'", just like what it does when we say
import 'nothing';
or
import {nothing} from 'nothing';
or
import * as nothing from 'nothing';

Actual behavior:
Typescript compiler is successful without any error.

@RyanCavanaugh RyanCavanaugh added Breaking Change Would introduce errors in existing code Bug A bug in TypeScript labels Dec 11, 2017
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Dec 11, 2017
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Dec 11, 2017
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Dec 11, 2017

This has been the behavior since at least 1.8 so it's a bit of a scary breaking change... but it's definitely a bug that we're not treating it the same as import "nothing";. Decent first PR if anyone's interested

@DanielRosenwasser
Copy link
Member

Actually, import "nothing" also suffers from this problem. And this is a break for anyone who has ever used https://github.com/Microsoft/TypeScript-React-Starter in which users can import "./Foo.css".

@mhegazy
Copy link
Contributor

mhegazy commented Jan 4, 2018

We have left these unchecked to allow for uses where the module is a non-code module, e.g. .css. Users do that to allow for bundles to bundle such assets with your code.

The rational here is we care about modules mainly for type purposes. if we are not garbing any types from the modules, there is no reason to error.

It gets even more complicated to get these right with things like loader extensions, where the module name is not a file name but rather a loader + file, e.g. css!a.css.

It is widely used out in the wild, and the break will be big. for instance, here is the sample we shared with users for react that uses this pattern: https://github.com/Microsoft/TypeScript-React-Starter/blob/master/src/App.tsx#L2

In short, i think we are better off leaving this issue unaddressed, and the fix is not worth the breaking change at this point.

@mhegazy mhegazy modified the milestones: Community, TypeScript 2.9 Apr 18, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 18, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants