Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error: Debug Failure. False expression: Output generation failed" when Importing Custom Declarations File in Angular 2 Service

I have an old, yucky JavaScript file full of stuff that I need to make available to my Angular service, and I just cannot figure out how to do it. I'm suprised at how hard it is to find a tutorial for this. Maybe I'm just so out of the loop that I don't even know how to ask the question...

I've created a declaration file for it (let's say it's called oldstuff.d.ts).

clarification: this is a declaration file only. The actual code lives in a different file: oldstuff.js

At the top of my Angular service, I'm importing the declaration file like this:

import './oldstuff.d';

I am not doing anything else anywhere in the application to attempt to get the declaration file included.

This import is enough to get VS Code to recognize the definitions, and all the intellisense is working as I would expect.

In fact, I can even use the Angular CLI to build the project, and it seems to build OK.

However, as soon as I try to inject this service into a constructor elsewhere in the application, the build fails with the following error:

ERROR in ./src/app/oldstuff.d.ts
Module build failed: Error: Debug Failure. False expression: Output generation failed
    at Object.assert (c:\Projects\Angular\MyApp\node_modules\typescript\lib\typescript.js:3329:23)
    at Object.transpileModule (c:\Projects\Angular\MyApp\node_modules\typescript\lib\typescript.js:80449:18)
    at TypeScriptFileRefactor.transpile (c:\Projects\Angular\MyApp\node_modules\@ngtools\webpack\src\refactor.js:166:27)
    at Promise.resolve.then.then.then.then (c:\Projects\Angular\MyApp\node_modules\@ngtools\webpack\src\loader.js:414:37)
 @ ./src/app/my-app.module.ts 23:0-34
 @ ./src/main.ts
 @ multi ./src/main.ts

I have googled both for that specific error message, and for generic information on how to include declaration files, and I'm coming up dry.

Here are some of the things I've looked at:

  • https://angular.io/guide/typescript-configuration
  • https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html
  • https://www.bennadel.com/blog/3169-adding-custom-typings-files-d-ts-in-an-angular-2-typescript-application.htm
  • https://github.com/angular/angular/issues/11567
  • https://github.com/angular/angular-cli/issues/6736
  • https://github.com/s-panferov/awesome-typescript-loader/issues/225

Am I hitting a legit bug, or am I doing it completely wrong?

like image 900
Rolandus Avatar asked Sep 13 '17 21:09

Rolandus


1 Answers

Well, this seems really dumb, but all I had to do was remove the letter 'd' from the name of the file.

So, instead of this:

//actual filename: oldstuff.d.ts
import './oldstuff.d';

I have this:

//actual filename: oldstuff.ts
import './oldstuff'

And now it builds and works at runtime as expected. I don't understand Typescript well enough to understand whether that's expected behavior or not.

like image 193
Rolandus Avatar answered Nov 15 '22 16:11

Rolandus