我将 Ionic 3 项目升级为 Ionic 4 项目。使用“ionic serve”启动服务器时,我总是会收到上述错误。
我试过很多东西,例如:
在
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;
在头部添加
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/