reika reika - 1 month ago 361
TypeScript Question

Angular EventEmitter not found

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.

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? ./src/main.ts

Here is the code.

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

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.

Answer Source

Try this:

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