question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@angular-builders/custom-webpack:karma fails compiling TypeScript with activated strictNullChecks

See original GitHub issue

Describe the Bug

When a custom webpack config is provided written in TypeScript, @angular-builders/custom-webpack:karma throws an error if strictNullChecks are activated.

Minimal Reproduction

https://github.com/Markus-Ende/custom-webpack-builder-strictnullchecks-issue

  1. Clone & install repo
  2. run npm test.

(Deactive strictNullChecks in tsconfig.json to see, that the Error does only occur when activated)

Expected Behavior

Karma tests should run normally.

Error output

An unhandled exception occurred: ⨯ Unable to compile TypeScript:
webpack-config/extra-webpack.config.ts:2:54 - error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'Function'.

2 export default (config) => __awaiter(void 0, void 0, void 0, function* () {
                                                       ~~~~~~

See "/tmp/ng-Hi3EUl/angular-errors.log" for further details.

Environment


Libs
- @angular/core version: 9.1.9
- @angular-devkit/build-angular version: 0.901.7
- @angular-builders/custom-webpack version: 9.1.0

For Tooling issues:
- Node version: v12.16.1
- Platform:  Linux

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
just-jebcommented, Nov 16, 2020

The issue is that there are two instances of ts-node registered during the run. No out of the box solution at the moment. As a first step I’d try to remove your direct ts-node dependency and if that doesn’t help I’d just use Promise.then syntax.

1reaction
just-jebcommented, Jun 3, 2020

Ok. A few findings:

  1. The problem is with async keyword - once it is removed the problem goes away. So as a workaround you can just use plain Promise syntax.
  2. I can disable the type checking for the config file by passing transpileOnly option into register. Not sure it’s the right decision though (it is basically your only indication for type errors in your config).
  3. Another solution would be to have a separate tsconfig.json (built in the builder) for config transpilation. Not sure this is the right decision either, since I do want people to have control of it.
  4. I’d probably go with #2 or #3 if it was happening with all the commands. But it only happens with Karma and I don’t have any idea why. So I think it’s important to understand how Karma flow is different from the others before we take any actions.
Read more comments on GitHub >

github_iconTop Results From Across the Web

strictNullChecks - TSConfig Option - TypeScript
When strictNullChecks is true , null and undefined have their own distinct types and you'll get a type error if you try to...
Read more >
Typescript strictNullChecks with limited scope - Stack Overflow
Is there a way to declare a directory / file / module / class as abiding by strictNullChecks, even when the overall project...
Read more >
StrictNullChecks in TypeScript - Best Practice - tsmean
The 'strictNullChecks' TypeScript compiler option allow you to catch null pointers at compile time, providing you with extra safety for your application.
Read more >
Angular & TypeScript: Writing Safer Code with strictNullChecks
TypeScript with strict null checking enabled feels even more comfortable for ... of the TypeScript compiler with strictNullChecks turned on: ...
Read more >
Writing safer code with TypeScript strict null checks & type ...
It can be enabled by adding the –strictNullChecks flag as an ... Let's have a look at an example that will fail during...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found