Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A with webpack v5 bundled unchanged angular app, does not work anymore #11635

Closed
deleonio opened this issue Oct 11, 2020 · 8 comments
Closed

Comments

@deleonio
Copy link

deleonio commented Oct 11, 2020

Bug report

A successful bundled angular app, does not work after webpack 5 upgrade.

What is the current behavior?

Link: https://github.modevel.de/poc/webpack/#series
image

If the current behavior is a bug, please provide the steps to reproduce.

Please use the bash commands to reproduce the same code.

Console:

mkdir angular-bug
cd angular-bug
npm i @leanup/cli@webpack @leanup/cli-angular@webpack
npx lean create -o
npm run build

Open manuel the dist/index.html.

If you need more transparency in the webpack.config: https://github.com/leanupjs/leanup/blob/0e7d4589ab78ca534bc8a13ec7760be9710576cf/packages/cli/core/src/webpack.config.ts#L135

What is the expected behavior?

image

Other relevant information:
webpack version: ^5
Node.js version: ^4
Operating System: win / unix
Additional tools:

  • webpack-cli ^4
@TheLarkInn
Copy link
Member

(cc @StephenFluin @hansl we got this in from Twitter triage)

@StephenFluin
Copy link

CC: @kyliau @mgechev

@sokra
Copy link
Member

sokra commented Oct 12, 2020

Not quite sure what's going on here...

That's the unmangled error message:

Uncaught NullInjectorError: StaticInjectorError(Platform: core)[CompilerFactory]: 
  NullInjectorError: No provider for CompilerFactory!
    at NullInjector.get (webpack://angular-bug/./node_modules/@angular/core/fesm2015/core.js?:1121:27)
    at resolveToken (webpack://angular-bug/./node_modules/@angular/core/fesm2015/core.js?:11801:24)
    at tryResolveToken (webpack://angular-bug/./node_modules/@angular/core/fesm2015/core.js?:11746:16)
    at StaticInjector.get (webpack://angular-bug/./node_modules/@angular/core/fesm2015/core.js?:11641:20)
    at compileNgModuleFactory__PRE_R3__ (webpack://angular-bug/./node_modules/@angular/core/fesm2015/core.js?:27922:38)
    at PlatformRef.bootstrapModule (webpack://angular-bug/./node_modules/@angular/core/fesm2015/core.js?:28166:16)
    at eval (webpack://angular-bug/./src/angular.main.js?:21:84)
    at Object.6466 (file:///C:/Repos/_/angular-bug/dist/app.js:3050:1)
    at __webpack_require__ (file:///C:/Repos/_/angular-bug/dist/app.js:3467:42)
    at eval (webpack://angular-bug/./src/main.ts?:1:71)

Seems like not CompilerFactory is available. I figured that the webpack 5 version uses compileNgModuleFactory__PRE_R3__ and the webpack 4 version uses compileNgModuleFactory__POST_R3__

I have not deep knownledge about angular so only guessing:

CompilerFactory and compileNgModuleFactory__PRE_R3__ should not be used in production build. Seems like your own sources are not being ivy-compiled. Probably something related to the AngularCompilerPlugin.

Maybe someone from the angular team as more insight into that...

@sokra
Copy link
Member

sokra commented Oct 12, 2020

Ok I found the problem in AngularCompilerPlugin:

It hooks into resolverFactory.hooks.resolveOptions and tries to "fix" the mainFields, but it doesn't "fix" byDependency.xxx.mainFields. It could just use our own merge function: cleverMerge(resolveOptions, { mainFields: [...ivyMainFields, "..."] } ) which handles this correctly.

@alexander-akait
Copy link
Member

Answer above and we fix it, feel free to feedback

@sokra
Copy link
Member

sokra commented Oct 14, 2020

I would like to track this until this is fixed in AngularCompilerPlugin

@deleonio
Copy link
Author

deleonio commented Oct 16, 2020

@sokra
Copy link
Member

sokra commented Oct 16, 2020

fixed by angular/angular-cli#19062

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants