我已经使用Visual Studio Angular Template
创建了项目。我最近把我的Angular
从6更新到了7,把Typescript
更新到了3.1.6。还将Webpack
从3.8.1升级到3.12.0。
现在,当我尝试使用webpack命令进行编译时,我得到了以下错误
ERROR in [at-loader] ./ClientApp/boot.server.ts:30:17
TS2304: Cannot find name 'setImmediate'.
此错误是由boot.server.ts代码引发的
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();
});
});
});
});
我试着解决这个问题已经有一段时间了,但是没有成功。任何idea>
发布于 2019-01-04 09:28:26
我也遇到了同样的问题,但我想我知道问题出在哪里了。我必须为node安装类型声明文件。
在package.json中添加
"@types/node": "10.12.18",
还要确保您的tsconfig.json正确地包含了类型文件。如果您手动显式包含类型文件,请将'node‘添加到您的“类型”数组中:
"types": ["node"]
或者使用"typeRoots“属性:
"typeRoots": [ "node_modules/@types" ]
我更喜欢第二个选项,因为这样您安装的所有@type包都会自动被您的IDE识别。
这个问题是关于一个类似的问题,答案比我更详细:typescript getting error TS2304: cannot find name ' require'
发布于 2019-08-14 18:31:55
您可以在setImmediate之前使用(window)
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();
});
});
});
发布于 2018-12-05 08:46:51
对不起,是我的错。从cmd或powershell运行"npm install“命令。它应该可以解决这个问题。
https://stackoverflow.com/questions/53622757
复制相似问题