gpt4 book ai didi

javascript - src/polyfills.ts(73,1) : error TS2304: Cannot find name 'global' . [ng] src/polyfills.ts(73,17) 中出现错误时出现 web-pack 错误:

转载 作者:搜寻专家 更新时间:2023-10-30 21:44:58 26 4
gpt4 key购买 nike

我将 Ionic 3 项目升级为 Ionic 4 项目。使用“ionic serve”启动服务器时,我总是会收到上述错误。

我试过很多东西,例如:

  1. polyfills.ts 文件中,

    (window as any).process = {
    env: { DEBUG: undefined },
    };
    (window as any).global = window;
    (window as any).process = window;
    (window as any).process.browser = true;
    (window as any).process.version = '';
    (window as any).process.versions = {node: false};
    global.Buffer = global.Buffer || require('buffer').Buffer;
  2. 在头部添加script标签,定义全局等

我的 tsconfig.json 文件

{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}

均无效。

如何解决错误?

最佳答案

将此添加到您的 index.html

    <script>
if (global === undefined) {
var global = window;
}
</script>

关于javascript - src/polyfills.ts(73,1) : error TS2304: Cannot find name 'global' . [ng] src/polyfills.ts(73,17) 中出现错误时出现 web-pack 错误:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57125976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com