首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更新后,webpack和Angular收到错误,无法找到名称'setImmediate‘

更新后,webpack和Angular收到错误,无法找到名称'setImmediate‘
EN

Stack Overflow用户
提问于 2018-12-05 07:07:21
回答 3查看 1.6K关注 0票数 1

我已经使用Visual Studio Angular Template创建了项目。我最近把我的Angular从6更新到了7,把Typescript更新到了3.1.6。还将Webpack从3.8.1升级到3.12.0

现在,当我尝试使用webpack命令进行编译时,我得到了以下错误

代码语言:javascript
复制
ERROR in [at-loader] ./ClientApp/boot.server.ts:30:17
        TS2304: Cannot find name 'setImmediate'.

此错误是由boot.server.ts代码引发的

代码语言:javascript
复制
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>

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-01-04 09:28:26

我也遇到了同样的问题,但我想我知道问题出在哪里了。我必须为node安装类型声明文件。

在package.json中添加

代码语言:javascript
复制
"@types/node": "10.12.18",

还要确保您的tsconfig.json正确地包含了类型文件。如果您手动显式包含类型文件,请将'node‘添加到您的“类型”数组中:

代码语言:javascript
复制
"types": ["node"]

或者使用"typeRoots“属性:

代码语言:javascript
复制
"typeRoots": [ "node_modules/@types" ]

我更喜欢第二个选项,因为这样您安装的所有@type包都会自动被您的IDE识别。

这个问题是关于一个类似的问题,答案比我更详细:typescript getting error TS2304: cannot find name ' require'

票数 2
EN

Stack Overflow用户

发布于 2019-08-14 18:31:55

您可以在setImmediate之前使用(window)

代码语言:javascript
复制
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();
            });
        });
    });
票数 0
EN

Stack Overflow用户

发布于 2018-12-05 08:46:51

对不起,是我的错。从cmd或powershell运行"npm install“命令。它应该可以解决这个问题。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53622757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档