PatrickJS/NG6-starter

_angular2.default.module is not a function

mcelotti opened this issue · 1 comments

I'm using this project (with your original webpack conf) in two different angular apps (let's call them "pA" and "pB"), now I'd like to import pB in pA as a node module in order to use some components that pB has.
I've succesfully setup pA package.json with pB dependency, and pB has an index.js with './dist/app.bundle' module export.
Compiling and building for both projects is ok, but when I run pA in the browser I get:
_angular2.default.module is not a function

If I remove the angular dependency then pA loads just fine so the problem is with my pB module.

Thank you for the support and for the project,
Marco

Ok, the solution is to remove "import angular from 'angular';" in all the files in pB.
This works fine importing the dist bundle (ie a single transpiled file having all the pB code, including vendor's code).
Anyway to use pB components in pA I moved to another solution that I like more and which consist in importing the pB module source code (no dist) just like a normal dependency (in package.json) and telling webpack babel loader to exclude all modules except pB:

{ test: /\.js$/, exclude: /node_modules\/(?!(pB)\/).*/, loader: 'ng-annotate!babel' }

Hope this is useful to somebody looking for the same setup.
Thank you!