2

I've been following the Angular upgrade guide to create a hybrid AngularJS/Angular app, but I'm falling at the first hurdle.

I get the following error:

Uncaught Error: Can't resolve all parameters for AppModule: (?).

Here's my app.module.ts file:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UpgradeModule } from '@angular/upgrade/static';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

@NgModule({
    imports: [
        BrowserModule,
        UpgradeModule
    ]
})

export class AppModule {
    constructor(private upgrade: UpgradeModule) {}

    ngDoBootstrap() {
        this.upgrade.bootstrap(document.body, ['MyApp'], { strictDi: true });
    }
}

platformBrowserDynamic().bootstrapModule(AppModule);

It's worth pointing out that I'm using webpack, and I've tried aliasing the @angular/upgrade/static package as follows:

resolve: {
    extensions: ['.ts', '.js'],
    alias: {
        "@angular/upgrade/static": "@angular/upgrade/bundles/upgrade-static.umd.js"
    }
},

But this doesn't seem to help at all.

Any ideas what's going on here?

Leon
  • 715
  • 1
  • 8
  • 22
  • *side note* - why not use `angular-cli` instead of webpack? – Igor Mar 13 '18 at 20:39
  • @Igor I'm using Laravel Mix, and I figured it just made sense to run it through there – Leon Mar 13 '18 at 21:00
  • Mine looks pretty much the same, but I'm using the cli. I would see if you can spawn off a test project and get it working with the cli quickly. If it works then it's probably something wrong with your webpack config. – cjablonski76 Mar 14 '18 at 23:48

2 Answers2

3

For me, the specific part of the article How To Upgrade from AngularJS to Angular with ngUpgrade which helped was to import zone.js and reflect-metadata:

import 'zone.js';
import 'reflect-metadata';
Tom Robinson
  • 8,348
  • 9
  • 58
  • 102
  • 1
    I have no idea why this answer is so difficult to find, I just spent the last 2 days trying to figure this out. Now to figure out why it doesn't actually bootstrap my AngularJS app.... at least I'm no longer getting the OP's error. – coppereyecat Jun 30 '21 at 16:44
0

I managed to figure this out through a combination of this article, and tweaking my tsconfig to match one generated by angular-cli.

Leon
  • 715
  • 1
  • 8
  • 22