In my .netcore app I upgraded my Typescript version from 2.4.1 to 3.2.4 and now I am receiving the error Cannot find name 'setImmediate' at compile time. The implementation I have below is basically straight from the Microsoft guide on pre-rendering.
export default createServerRenderer(params => {
const providers = [
{ provide: INITIAL_CONFIG, useValue: { document: '<app></app>', url: params.url } },
{ provide: APP_BASE_HREF, useValue: params.baseUrl },
{ provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
];
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const state = moduleRef.injector.get(PlatformState);
const zone = moduleRef.injector.get(NgZone);
return new Promise<RenderResult>((resolve, reject) => {
zone.onError.subscribe((errorInfo: any) => reject(errorInfo));
appRef.isStable.pipe(first(isStable => isStable)).subscribe(() => {
setImmediate(() => { // <!-- error here
resolve({
html: state.renderToString(),
globals: {
}
});
moduleRef.destroy();
});
});
});
});
});
I saw that there was a bug raised for this, however it is marked as resolved and merged. I also tried installing the setImmediate package and importing that, however that didn't work either. Anyone know how to resolve this ?
Non webpack:
Installing npm install --save-dev @types/node and then importing import '@types/node'; at the start of the file resolved this issue for me.
If you are using webpack then this will not work. Instead npm install --save-dev @types/node node then you will have to:
Go into your .tsconfig and add 'node':
{
"compilerOptions": {
"types": [..., "node" ],
...
}
}
do not import '@types/node'; this is for the reasons stated here:
@typespackages are stored in the@typesdirectory but they must never be manually imported. Rather, you need to import the dependency they correspond to from where that dependency is installed.@typespackages provide the type declarations for dependencies that do not otherwise provide them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With