3

I'm asking here because I could't find complete documentation online. The example here is too simple. I've an app with several components and some modules. After compile with ngc, I had lot of errors. The way I found to fix them was use relative paths. So I use 'moduleId: module.id,' in all my components. But now the compiler tells me: ' Cannot find name 'module' '

As I understand, that is becuase I'm declaring the following compile options for AoT:

{
  "compilerOptions": {
    "target": "es5",
   ---> "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },

  "angularCompilerOptions": {
   "genDir": "aot",
   "skipMetadataEmit" : true
 }
}

Instead of using "module": "commonjs",. How can I fix this?

How can I use relative paths at the same time I want to generate the AOT build?

thanks!

Sr Julien
  • 494
  • 1
  • 8
  • 27
  • If you use webpack, you could check angular2-template-loader. Then in your component metadata just set like that - templateUrl: './yourtemplate.component.html'. There is a lot of troubles with ngc still :( – Kamil Myśliwiec Oct 11 '16 at 08:53
  • It's possible to create one js file with the whole app (minfied) using webpack? That is what I'm looking for .. a process to create one file with the whole app (js, html, css). – Simon De Uvarow Oct 12 '16 at 18:50
  • Yes of cours. Take a look here - https://angular.io/docs/ts/latest/guide/webpack.html – Kamil Myśliwiec Oct 12 '16 at 19:40

1 Answers1

0

A quick (and maybe dirty) fix is just to write the path directly as a string in the moduleId parameter.

So instead of:

moduleId: module.id

Write:

moduleId: 'path/to/my/app/'

This you can use with Component Relative Paths during development, and when creating the AoT bundle ngc won't complain about not finding module.id.

Peter Salomonsen
  • 5,525
  • 2
  • 24
  • 38