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 if module not found #9132

Closed
OliverJAsh opened this issue Jun 13, 2016 · 8 comments
Closed

Error if module not found #9132

OliverJAsh opened this issue Jun 13, 2016 · 8 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@OliverJAsh
Copy link
Contributor

If I try to import a module and TS doesn't find it, I don't get any errors. allowJs is enabled.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 13, 2016

You need to provide to provide more information than this...

What is your project configuration? How do you know that TS doesn't find it, what problems is this causing? What version of TypeScript are you using? What is an example of a file that does not exist?

Are we just supposed to guess?

Just randomly guessing, based on other questions you have asked, you are trying to import JavaScript files using the import 'something.js'; for its side affects... In this case, TypeScript assumes you know what you are doing and since it does not need to resolve the module since it isn't importing any of that into the scope of the program it is compiling, it does not attempt to do so and just passes that to the emit.

Resolving that at design time and throwing an error, would cause a lot of problems for people attempting to import 3rd party libraries which are not resolvable at design time.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 13, 2016

There are no semantic errors reported in JS files. only in .ts files. If i am guessing correctly you are expecting this error in .js file.

The rational here is users could have existing JS files with dynamic behavior, e.g. require("myModule"+getModuleSuffix()); that the compiler has no way to understand. so instead of giving users errors for working code, we chose not to report these errors in JS files.

I understand that leaves more to be desired, we have #6802 tracking making these JS errors more configurable, so you can decide whether or not you want to see these errors.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 13, 2016

leaving this as needing more info. as @kitsonk noted, more context would be needed to assess or investigate this issue.

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Jun 13, 2016
@OliverJAsh
Copy link
Contributor Author

Here is more info.

I have enabled allowJs. In my TS file, I have this import, for a non-existent file:

import "./foo";

TS does not give me any errors.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 22, 2016

@OliverJAsh as stated above:

Just randomly guessing, based on other questions you have asked, you are trying to import JavaScript files using the import 'something.js'; for its side affects... In this case, TypeScript assumes you know what you are doing and since it does not need to resolve the module since it isn't importing any of that into the scope of the program it is compiling, it does not attempt to do so and just passes that to the emit.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 22, 2016

I think this is the same as #6802. The compiler has this information, it just decides not to report these errors in JS files. we will need some error configuration infrastructure to make them surface.

@mhegazy mhegazy removed the Needs More Info The issue still hasn't been fully clarified label Jun 22, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Jun 22, 2016

closing in favor of #6802

@mhegazy mhegazy closed this as completed Jun 22, 2016
@mhegazy mhegazy added Suggestion An idea for TypeScript Duplicate An existing issue was already created labels Jun 22, 2016
@kitsonk
Copy link
Contributor

kitsonk commented Jun 23, 2016

The compiler has this information, it just decides not to report these errors in JS files. we will need some error configuration infrastructure to make them surface.

#6802 is broad, but likely the right place. I will mention it there too that if that were the case, like this one, not all of these errors are fatal and even in an IDE. I suspect the import 'foo.js'; use case is in a .ts file is often used to load external libraries at run-time which are often not located in a resolvable location at run-time and that change in behaviour would have some significant consequences, as there is not syntatical notation to differentiate between those "just trust me, load this" and "actually, even though this import will have no design time affect on my code, I want tsc to error..."

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants