Angular AOT Relative paths in components

泪湿孤枕 提交于 2019-12-10 10:16:59

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/39964779/angular-aot-relative-paths-in-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!