-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix: set correct module format for TypeScript #3139
Conversation
When having a root tsconfig which is used by the application with module value other than `commonjs` it would fail if you have an `import` statement with an error `SyntaxError: Unexpected token` This is due that under node module target should be set for `commonjs`
e436121
to
5394a65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a test that fails without this change and passes with it?
@johnjbarton I'd happily do that but where should it be placed? Also this would imply of adding |
No, I'm not keen on more deps for this small feature. Why isn't the default |
I have create a small repo illustrating this;
If you remove this https://github.com/alan-agius4/karma-config-ts-issue/blob/master/tsconfig.json#L3 karma won't throw an error. However in most cases if you are developing a web app you'd want this module format. Changing this to |
Thanks for the added information. I understand that your approach will work for many users. However, I wonder if we can find a different solution to the original problem. Any values we put in the code to override Couldn't we update the docs to explain how to use TypeScript configs without the ts-node hack in karma? If a user writes a file require('ts-node').register({ compilerOptions: { module: 'commonjs' } });
require('./karma.conf.ts'); then the original problem is solved and users can simply customize the solution for other cases without waiting for upstream changes. |
@johnjbarton, I can certainly do that. Where would you see this doc to fit? |
Near the top of https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md To balance the goal of clarity and users noticing two options for loading TS configs, consider a short sentence near the top pointing to the customizable solution and then the customizable solution at the end of the Overview. |
super-seeded by #3140 |
When having a root tsconfig which is used by the application with module value other than
commonjs
it would fail if you have animport
statement in the config ts file with an errorSyntaxError: Unexpected token
This is due that under node module target should be set forcommonjs
Relates to angular/angular-cli#12294