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

标签 javascript node.js angular typescript ionic-framework

我将 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/

相关文章:

javascript - 使用 Node Stream 连接音频文件

javascript - 预期有一个符合条件的请求

html - Angular 2 形式 "Cannot Find Control"

javascript - JQUERY 在同级之前追加数据

javascript - 如何在 Canvas 上重新着色灰度图像

javascript - Chartjs 更新点标题

javascript - $.ajax if 条件

使用 Prisma 执行 MySQL 查询花费的时间太长

mysql - 更新 Node mysql 中的行时出现问题

html - Angular src 图像的延迟加载