Sentry-javascript: Got error Cannot find name 'unknown' when buildind an Angular 6 app

Created on 21 Nov 2019  ·  3Comments  ·  Source: getsentry/sentry-javascript

Package + Version

  • [X] @sentry/browser
  • [ ] @sentry/node
  • [ ] raven-js
  • [ ] raven-node _(raven for node)_
  • [ ] other:

Version:

5.9.1

Description

Hi, I have an Angular 6 project in which we are using "@sentry/browser": "^5.0.6". This project uses GitLab CI tools to build a docker image for running our tests and deploy it. Today, we tried to launch the jobs and the typescript build failed with the following error code:

ERROR in node_modules/@sentry/utils/dist/misc.d.ts(89,48): error TS2304: Cannot find name 'unknown'.

The weirdest thing is that last time we run the jobs (October 2nd) everything was fine and we haven't change any single line of our project & configuration since then.

Do you have any clue? I'm pretty sure that it is something really stupid...

Our package.json is:

{
  "name": "tool-front",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --disable-host-check --host=0.0.0.0",
    "build": "ng build",
    "test": "ng test",
    "lint": "./node_modules/eslint/bin/eslint.js \"./src/**/*.ts\" --quiet",
  },
  "private": true,
  "dependencies": {
    "angular2-query-builder": "0.3.1",
    "@angular/animations": "^6.1.10",
    "@angular/cdk": "^6.3.2",
    "@angular/common": "^6.1.10",
    "@angular/compiler": "^6.1.10",
    "@angular/core": "^6.1.10",
    "@angular/flex-layout": "6.0.0-beta.16",
    "@angular/forms": "^6.1.10",
    "@angular/http": "^6.1.10",
    "@angular/material": "^6.4.7",
    "@angular/material-moment-adapter": "^6.4.7",
    "@angular/platform-browser": "^6.1.10",
    "@angular/platform-browser-dynamic": "^6.1.10",
    "@angular/router": "^6.1.10",
    "@asymmetrik/ngx-leaflet": "^4.0.0",
    "@sentry/browser": "^5.9.1",
    "@sentry/types": "^5.7.1",
    "@sentry/typescript": "^5.7.1",
    "@zxing/ngx-scanner": "1.3.0",
    "deepmerge": "^3.2.0",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "leaflet": "^1.3.1",
    "mat-progress-buttons": "^6.0.1",
    "moment": "^2.22.2",
    "ng-dynamic-component": "^4.0.2",
    "ng2-file-upload": "^1.3.0",
    "ng2-nvd3": "^2.0.0",
    "ngx-init": "^0.1.0",
    "ngx-mat-select-search": "^1.2.0",
    "ngx-papaparse": "^3.0.2",
    "rxjs": "6.2.2",
    "uuid": "^3.3.2",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "6.2.8",
    "@angular/compiler-cli": "^6.1.10",
    "@angular/language-service": "^6.1.10",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "^2.0.6",
    "@types/leaflet": "^1.2.0",
    "@types/node": "~6.0.101",
    "@typescript-eslint/eslint-plugin": "^1.9.0",
    "@typescript-eslint/parser": "^1.4.2",
    "codelyzer": "^4.4.2",
    "concurrently": "^3.5.1",
    "eslint": "^5.15.1",
    "eslint-config-prettier": "^4.1.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "json-server": "^0.12.1",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.1",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.9.0",
    "webpack": "^4.28.3"
  }
}

and our tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "module": "es2015",
    "baseUrl": "./"
  }
}

Thanks a lot, if you need further information, just ask.

Edit: Of course, I tried to update the sentry version to the latest one (5.9.1 and got the same results

Needs Information Discussion

Most helpful comment

@franciscovelez you can easily workaround it by declaring unknown type yourself like so:

declare global {
  type unknown = any
}

ooor to be more exact if you want:

export type mixed = { [key: string]: any } | object | number | string | boolean | symbol | undefined | null | void

declare global {
  type unknown = mixed
}

All 3 comments

unknown is a type that was introduced in Typescript 3 and you are using Typescript 2. However, we had unknown references in the codebase since v4 of the SDK, so I'm not sure how it could work for you before? 🤔

Hi kamilogorek, as you said we use TypeScript 2.9. I have been playing with npm and the sentry/browser versions today and it seems that the last version it works for me is @sentry/browser: 5.6.3. I have checked the release history in npm (https://www.npmjs.com/package/@sentry/browser) and I see that @sentry/browser: 5.7.0 was released a week after my last successful deploy, so everything makes sense to me.

For now I'll keep my package in the 5.6.3 version.

Thanks for your help

@franciscovelez you can easily workaround it by declaring unknown type yourself like so:

declare global {
  type unknown = any
}

ooor to be more exact if you want:

export type mixed = { [key: string]: any } | object | number | string | boolean | symbol | undefined | null | void

declare global {
  type unknown = mixed
}
Was this page helpful?
0 / 5 - 0 ratings