1

I've project created using Visual Studio Angular Template. I recently updated my Angular from 6 to 7 and Typescript to 3.1.6. Also upgraded Webpack from 3.8.1 to 3.12.0.

Now when I try to compile using webpack command I get the following error

ERROR in [at-loader] ./ClientApp/boot.server.ts:30:17
        TS2304: Cannot find name 'setImmediate'.

This error is thrown from boot.server.ts code

return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
        const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
        const state = moduleRef.injector.get(PlatformState);
        const zone: NgZone = moduleRef.injector.get(NgZone);

        return new Promise<RenderResult>((resolve, reject) => {
            zone.onError.subscribe((errorInfo: any) => reject(errorInfo));
            appRef.isStable.pipe(first(isStable => isStable)).subscribe(() => {
                // Because 'onStable' fires before 'onError', we have to delay slightly before
                // completing the request in case there's an error to report
                setImmediate(() => {
                    resolve({
                        html: state.renderToString()
                    });
                    moduleRef.destroy();
                });
            });
        });
    });

I'm trying to fix this for some time but no success. Any idea>

Nouman Bhatti
  • 1,341
  • 6
  • 28
  • 54

3 Answers3

2

I was having the same problem, but I think I figured out what the issue was. I had to install the typing declaration files for node.

In package.json add

"@types/node": "10.12.18",

Also make sure that your tsconfig.json is including the type files correctly. Either add 'node' to your "types" array if you are explicitly including the type files manually:

"types": ["node"]

or use the "typeRoots" property:

"typeRoots": [ "node_modules/@types" ]

I prefer the second option, as then all the @type packages you install will automatically get recognized by your IDE.


This question is for a similar issue, the answer there goes into more detail than I did: typescript getting error TS2304: cannot find name ' require'

Kyle
  • 89
  • 1
  • 7
1

You can use (window) before setImmediate

return new Promise<RenderResult>((resolve, reject) => {
        zone.onError.subscribe((errorInfo: any) => reject(errorInfo));
        appRef.isStable.first(isStable => isStable).subscribe(() => {
            // Because 'onStable' fires before 'onError', we have to delay slightly before
            // completing the request in case there's an error to report
            (<any>window).setImmediate(() => {
                resolve({
                    html: state.renderToString()
                });
                moduleRef.destroy();
            });
        });
    });
-1

sorry my bad. run "npm install" command from cmd or powershell. it should fix the issue.