angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

AoT can't do a direct import/export of a module from another ngc'd library

Open aaronleestic opened this issue 9 years ago • 5 comments

Please provide us with the following information:

OS?

Mac OSX El Capitan

Versions.

Angular 2.4.4, CLI Beta.24

Repro steps.

Created some NgModule and compiled it using NGC. tsconfig-aot.json:

{
  "compilerOptions": {
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2015",
      "dom"
    ],
    "noImplicitAny": false,
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "mapRoot": "",
    "outDir": "./dist",
    "stripInternal": true,
    "skipLibCheck": true,
    "baseUrl": ""
  },
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "./vendor.ts",
    "./polyfills.ts"
  ],
  "files": [
    "src/app/index.ts", ...
  ],
  "angularCompilerOptions": {
    "strictMetadataEmit": true,
    "debug": true
  }
}

The compiled NgModule is then imported and lazy loaded in another CLI app,

app.routes.ts:

 ... { path: 'auth', loadChildren: 'path/to/auth/module#AuthModule' } ...

path/to/auth/module.ts: export { AuthModule } from "client-angular2-components/dist/pages/auth";

The log given by the failure.

ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve '/Users/aaron/repos/my-app/src/$$_gendir/app/pages/auth/module.ngfactory.ts' in '/Users/aaron/repos/my-app/src/$$_gendir'
 @ ./src/$$_gendir async
 @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi main

Mention any other details that might be useful.

App and imported pages work fine when ng serve without AoT. Only when --aot flag enabled.

Current workaround is to wrap the imported AuthModule in another @NgModule({imports: [..]}) and have the route point to the wrapper module instead.

aaronleestic avatar Jan 20 '17 18:01 aaronleestic

@aaronleeucla maybe you can provide the module from the imported ngModule? I followed this pattern with my component lib and was able to get around the above. Then when you import you can use the CbVdlModule.forRoot() syntax.

export class CbVdlModule {
  public static forRoot(): ModuleWithProviders {
    return {ngModule: CbVdlModule};
  }
}

zackarychapple avatar Jan 23 '17 13:01 zackarychapple

I think this might be fixed in master by @filipesilva changes to the way lazy modules are sent to webpack. Filipe?

hansl avatar Jan 24 '17 20:01 hansl

@aaronleeucla I can test against latest master if you give me a repo I can use.

filipesilva avatar Jan 25 '17 08:01 filipesilva

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

filipesilva avatar May 22 '17 15:05 filipesilva

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.