user3471528
user3471528

Reputation: 3053

Types not found

I just updated angular-cli (v1.1) and created a new project using ng new MyProj. Then I added and installed two dependencies to the project.json file:

"dependencies": {
    ...
    "toastr": "2.1.2",
    "spin": "0.0.1"
  },
  "devDependencies": {
    ...
    "@types/toastr": "2.1.32",
    "@types/spin": "2.3.30",
    ...
    "typescript": "~2.3.3"
  }

Then I updated the autogenerated app.component.ts adding this constructor:

constructor() {
    toastr.success('Hi')
}

The IDE (visual studio code) do not return any error but when I serve the application using ng serve I get the following error:

ERROR in ../A/src/app/app.component.ts (15,5): C annot find name 'toastr'.

I really cannot figure out what is wrong with that.

Thanks a lot

Upvotes: 2

Views: 5704

Answers (2)

user3471528
user3471528

Reputation: 3053

I solved the problem removing types from tsconfig.app.json. This is the new configuration:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "outDir": "../out-tsc/app",
        "module": "es2015",
        "baseUrl": ""
    },
    "exclude": [
        "test.ts",
        "**/*.spec.ts"
    ]
}

Upvotes: 7

DarkNeuron
DarkNeuron

Reputation: 8711

Try doing import * as toastr from 'toastr' or import toastr from 'toastr' - the latter is if it has a default export.

Upvotes: 0

Related Questions