Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

431
Visualizações
After upgrade to Angular 9 cannot find variable in typings file

I have a reference to an external logging component (referenced in a js file), which I have defined in a typings file

typings.d.ts

declare var LogglyTracker;

I have upgraded my angular application from version 8 to 9, and now when I run ng build, I get the following error

ERROR in src/app/error/loggly.service.ts:13:29 - error TS2304: Cannot find name 'LogglyTracker'.

Does anyone know what the recommended way to fix this problem is? This code worked fine in Angular 8.

@Injectable()
export class LogglyLoggerService {

// https://github.com/loggly/loggly-jslogger
private loggly: any = new LogglyTracker(); //!! Error here
}
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Had the same problem after migrating from Angular 7 to Angular 9.

I personally just had to add one line in tsconfig.app.json.

Before:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "outDir": "../out-tsc/app",
        "types": [
            "node"
        ]
    },
    "files": [
        "main.ts",
        "polyfills.ts"
    ],
    "include": [
        "src/**/*.d.ts"
    ]
}

After:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "outDir": "../out-tsc/app",
        "types": [
            "node"
        ]
    },
    "files": [
        "main.ts",
        "polyfills.ts"
    ],
    "include": [
        "src/**/*.d.ts",
        "typings.d.ts" // add this line
    ]
}

I assumed you already made changes in tsconfig.json before migrating to Angular 9. If not, here it is:

{
    ...
    "compilerOptions": {
        ...
        "typeRoots": [
            "node_modules/@types",
            "src/typings.d.ts"
        ],
        ...
    }
}
over 4 years ago · Santiago Trujillo Relatório

0

I had exactly the same problem as the author - after upgrade to Angular 9, my local type definitions were no longer found.

In Angular 8, I added references to them in tsconfig.json

"typeRoots": [
    "node_modules/@types",
    "../src/typings/my-lib/index.d.ts"
    "node_modules/@types"
  ]

After upgrading to Angular 9, my-lib was no longer found. I generated a new app using Angular 9 CLI, and found that 2 files reside in different locations:

  • src/tsconfig.app.json -> tsconfig.app.json
  • src/tsconfig.spec.json -> tsconfig.spec.json

I made similar change in my migrated project, updated references to these files in angular.json, and corrected pointers to other files in tsconfig.app.json and tsconfig.spec.json

As a result, my tsconfig.app.json looks like:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": ["jest"]
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

Note that all d.ts files placed under src directory will be pulled in automatically (no reference in typeRoots section of tsconfig.json is necesssary)

over 4 years ago · Santiago Trujillo Relatório

0

Well for me the resolution was to add the following to the top of service file:

/// <reference path="../../typings.d.ts" />

reference is apparently another way to import type definitions into code, more info here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda