Shakti Phartiyal
Shakti Phartiyal

Reputation: 6254

Import a module without its path in angular 6

I have a third party module named ng2-toastr, I moved it into one of my app folders and removed it from node modules and using npm uninstall ng2-toastr. Now I want to import it in my AppModule and other modules by its name (like I used to do when it was in node_modules) and not by its path, how can I do that?

Upvotes: 0

Views: 368

Answers (1)

Juan M. Medina
Juan M. Medina

Reputation: 638

You probably want to read this in detail http://www.typescriptlang.org/docs/handbook/module-resolution.html

Having said that, you can achieve this as noted on that document by adding a path to your tsconfig.json.

{
  "compilerOptions": {
    "baseUrl": ".", // This must be specified if "paths" is.
    "paths": {
      "yourmodule": ["path/to/yourmodule"] // This mapping is relative to "baseUrl"
    }
  }
}

Note stuff inside node_modules has a default tree walk methodology to do what you intend, which is why it worked when you had that in node_modules (also explained in detail in that document).

Upvotes: 1

Related Questions