-
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
allowJs: why is import "x.js"
being ignored?
#9070
Comments
Is there any workaround? I guess I could rename all of my files to .ts |
I guess the question is why do you have to be explicit about the file extension on your modules? I see you are outputting to AMD... it is considered not a good idea to specify the file extension in AMD, because of portability issues just like this. |
I have an app where some modules are TS, some are JS. I want to include all of them, but this bug means that currently, all my JS files are ignored. I'm being explicit in my example because I have two files, one in TS and one in JS, and I want to import both. The fact they have the same name is irrelevant. |
Name two different modules |
The issue persists even if the files have different names. |
But then you don't (and shouldn't) append |
I see, that seems to fix it! Thank you. On Fri, 10 Jun 2016 at 11:21 Kitson Kelly [email protected] wrote:
|
Now I have separate names, the modules are being included in the bundle. However, the AMD output is broken:
Requiring/importing |
@OliverJAsh did |
They have no import/export statements. Should TypeScript be adding them as dependencies to the outputted module if they are not detected to be a module? In my case I am gradually converting an app into modules, so it would be difficult to add export everywhere. |
there are two issues, first the the second is that the files are not considered modules, as @DanielRosenwasser noted. for these, consider adding an empty export statement in the JS files, e.g.: // ./src/console-log.js
console.log('console-log JS')
export {}; // makes it a module with that change, the output would look like: define("console-log", ["require", "exports"], function (require, exports) {
"use strict";
// ./src/console-log.ts
console.log('console-log TS');
});
define("console-log", ["require", "exports"], function (require, exports) {
"use strict";
// ./src/console-log.js
console.log('console-log JS');
});
define("main", ["require", "exports", "console-log", "console-log"], function (require, exports) {
"use strict";
console.log('console-log main');
}); The change that needs to be done on the TS compiler side, is to treat a file as module, if it was imported. this is more inline with the spec. we should file a different issue to track that. |
I think TypeScript should not allow the user to end up in the situation I did, with a broken AMD module. Could TypeScript throw an error/warn if you try to load a JS file that is not a module? |
@OliverJAsh, covered by #9082 |
I have a similar issue I posted in a StackOverflow question and then I stumbled across this -- it seems related, except I think my question points out that @mhegazy's suggestion actually does not produce the expected output posted. |
@mjohnsonengr is this a different issue. i have replied to your SO question. |
Error for non-module code used as module is tracked by #9082 |
@OliverJAsh The problems with explicit extension syntax are, as @kitsonk mentioned, name collision and loader issues, and also workflow toolchain issues. |
Source:
Config:
Output:
Notice that the output is missing the contents of the
./console-log.js
import.The text was updated successfully, but these errors were encountered: