18

I created a project by using Angular CLI, but when I try to use EventEmitter, it fails to compile with the error "Can't resolve '@angular/core/src/event_emitter'"

Here is the full error message

Failed to compile.

./src/app/app.component.ts
Module not found: Error: Can't resolve '@angular/core/src/event_emitter' in 'C:\xampp\htdocs\myapp\src\app'
@ ./src/app/app.component.ts 10:22-64
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

Here is the code.

import { Component } from '@angular/core';
import { EventEmitter } from '@angular/core/src/event_emitter';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  private eventemitter = new EventEmitter<string>();
  title = 'My Application';
}

The file "node_modules\@angular\core\src\event_emitter.d.ts" exits.

I deleted node_modules folder, cleared npm cache (by using --force) and reinstalled all modules again with npm install, but still getting the same error.

I have no idea what can cause this, and I unfortunately couldn't find anything on internet related to this. Any help would be appreciated.

2
  • 1
    I guess you are using vs code editor and this import statement was auto imported. Sometimes this went wrong.
    – zgue
    Dec 22, 2017 at 20:28
  • @zgue, exactly. It was because of VSCode importing wrong library.
    – reika
    Dec 22, 2017 at 20:35

2 Answers 2

23

Try this:

import { EventEmitter } from '@angular/core';
2
  • Thank you! But.... why? The documentation says that the import should be <import { EventEmitter } from '@angular/core/src/event_emitter';>
    – jfajunior
    May 2, 2018 at 7:26
  • 1
    Toootally unaware you needed EventEmitter on the receiving side... thanks so much! Feb 18, 2019 at 18:04
0

To try this :

@Output() deleteItem: EventEmitter<Item> = new EventEmitter();

I import use this :

import { Output, EventEmitter } from '@angular/core';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.