2

There's something I'm not sure to understand with ES6 module import and Angular (although it's not restrcited to Angular)

When I'm importing a component like this :

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

Ok I'm importing the Component class from @angular/core package.

But if I go to node_modules : there's no Component class file at the root of @angular/core. I can see some bundle, esm5, esm2015 and src packages and also files like core.d.ts at the root. How the module loader manages to understand where this Component is located ?

Thanks

1
  • 1
    If you don't specify a file name to import, index.ts/js will be used (@angular/core/index.ts). You can go from this file up the tree (there are many files that only export in between) Commented Jun 7, 2018 at 16:51

1 Answer 1

1

When you importing @angular/core module, it will look for package.json in the module root that is node_modules/@angular/core folder. And then look for main property which is the main entry point of the module. This is the file you want.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Ok than you. I can see that in package.json there's a main attribute (core.umd.js) and also a module attributre (core.js). Are they the same thing ?
@AntonBoarf There are different module coding pattern. So their source code are different in module system only.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.