question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng-tools/webpack unable to resolve app.module.ts.ngfactory

See original GitHub issue

OS?

Mac OSX (El Capitan)

Versions.

ng-tools/webpack: 1.2.4 node: v5.11.0 angular-cli: 2.4.4 webpack: 2.2.0

Repro steps.

Using a custom made webpack config file. Trying to use ng-tools/webpack plugin to generate a build using AOT.

The log given by the failure.

stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^
Error: ./src/client/app.ts
Module not found: Error: Can't resolve './aot/src/client/app.module.ts.ngfactory' in '/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client'
resolve './aot/src/client/app.module.ts.ngfactory' in '/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client'
  using description file: /Volumes/User/oliver/htdocs/tu-prestamo-2/package.json (relative path: ./src/client)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Volumes/User/oliver/htdocs/tu-prestamo-2/package.json (relative path: ./src/client)
    using description file: /Volumes/User/oliver/htdocs/tu-prestamo-2/package.json (relative path: ./src/client/aot/src/client/app.module.ts.ngfactory
)
      as directory
        /Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.js doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.ts doesn't exist
      .scss
        Field 'browser' doesn't contain a valid alias configuration
        /Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.scss doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.json doesn't exist
[/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory]
[/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory]
[/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.js]
[/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.ts]
[/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.scss]
[/Volumes/User/oliver/htdocs/tu-prestamo-2/src/client/aot/src/client/app.module.ts.ngfactory.json]
 @ ./src/client/app.ts 3:0-78

Mention any other details that might be useful.

app.module.ts:

import './polyfills.ts';

import { AppModule } from './app.module';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

declare var ENVIRONMENT: string; // Webpack DefinePlugin.

if (ENVIRONMENT === "production") {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

tsconfig.aot.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "es6",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "angularCompilerOptions": {
   "skipMetadataEmit" : true,
   "genDir": "./src/client/aot",
   "debug": true
 }
}

webpack.config:

...
  plugins: [
    new AotPlugin({
      tsConfigPath: './tsconfig.aot.json',
      entryModule: __dirname + '/src/client/app.module.ts#AppModule',
    }),
...

Would like to provide more useful information. But the trace stack is not very helpful.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
trekhlebcommented, Apr 11, 2017

@olivercs, I had similar error that was caused by .ts file extension that I’ve mentioned in entryModule configuration (it doesn’t matter whether entryModule is configured in webpack.config.js or in tsconfig.json).

So after I’ve removed .ts extension from my tsconfig.json entryModule configuration the error was gone.

Before:

"angularCompilerOptions": {
    "entryModule": "src/app/app.module.ts#AppModule"
}

After:

"angularCompilerOptions": {
    "entryModule": "src/app/app.module#AppModule"
}

I hope this info would be helpful to you.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

0 - Stack Overflow
ngcli 6.1.3 ERROR in ./src/main.ts - Can't resolve './app/app.module.ngfactory' · Ask Question.
Read more >
Google Groups
ClientApp/boot.browser.ts Module not found: Error: Can't resolve './app/app.browser.module.ngfactory'. 189 views. Skip to first unread message.
Read more >
Angular - Code with Mosh Forum
ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): Error: Emit attempted before Angular Webpack plugin ...
Read more >
ngtools/webpack: missing app.module.ngfactory-node.js
The thing about @ngtools/webpack is that it creates those .ngfactory files in memory. Therefore there is no need to have any main.aot.ts ....
Read more >
How to configure Webpack 4 with Angular 7: a complete guide
ts that only imports the application's third-party modules. polyfills.ts we need polyfills to run an Angular application in most browsers as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found