3

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

asked Jun 7, 2017 at 19:33
5
  • have you install this dependencies using npm install command? Commented Jun 7, 2017 at 19:36
  • also in angular you need to import and inject your npm modules first, follow angular2-toastr documentation for more info Commented Jun 7, 2017 at 19:39
  • Yes, I did use npm install. I'm not using Angular2.toastr. I'm just using the "original" js library, so it is not a module, it is just a js file. Commented Jun 8, 2017 at 5:01
  • if it is only js library then you need to include js and css in index.html file, then you can use toaster inside any component, without including it would not work Commented Jun 8, 2017 at 14:43
  • I have the same problem, are there any updates by now? :( Commented Aug 21, 2017 at 10:35

2 Answers 2

8

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"
 ]
}
answered Sep 7, 2017 at 8:22
Sign up to request clarification or add additional context in comments.

Comments

-1

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

answered Jun 22, 2017 at 15:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.