Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 升级到angular-6.x时,会给出;未捕获引用错误:未定义全局;_Javascript_Angular_Angular Cli_Angular6 - Fatal编程技术网

Javascript 升级到angular-6.x时,会给出;未捕获引用错误:未定义全局;

Javascript 升级到angular-6.x时,会给出;未捕获引用错误:未定义全局;,javascript,angular,angular-cli,angular6,Javascript,Angular,Angular Cli,Angular6,我将我的项目从angular-5.x升级到angular-6.x,它开始给出以下错误,甚至虚拟全局变量的创建也不能像这里给出的那样工作 错误如下: Uncaught ReferenceError: global is not defined at Object../node_modules/has-binary2/index.js (index.js:10) at __webpack_require__ (bootstrap:81) at Object../node_mo

我将我的项目从angular-5.x升级到angular-6.x,它开始给出以下错误,甚至虚拟全局变量的创建也不能像这里给出的那样工作

错误如下:

Uncaught ReferenceError: global is not defined
    at Object../node_modules/has-binary2/index.js (index.js:10)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/socket.io-parser/index.js (index.js:8)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/socket.io-client/lib/index.js (index.js:7)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app4pc/apiConnection/services/ApiConnectionServer.ts (auth.interceptor.ts:8)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app4pc/apiConnection/toServer.module.ts (ApiConnectionServer.ts:11)
    at __webpack_require__ (bootstrap:81)
解决此问题后,我得到以下错误:

Uncaught ReferenceError: process is not defined
    at Object../node_modules/process-nextick-args/index.js (index.js:3)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:26)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/readable-stream/readable-browser.js (readable-browser.js:1)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/simple-peer/index.js (index.js:7)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/util/services/call.services.ts (notification.service.ts:12)
    at __webpack_require__ (bootstrap:81)    

并继续进行。

在起始页中添加以下代码,例如index.html

var global=global | |窗口;
var Buffer=Buffer | |[];
var过程=过程| |{
环境:{DEBUG:undefined},
版本:[]
};
例如:


客户
var global=全局| |窗口;
var Buffer=Buffer | |[];
var过程=过程| |{
环境:{DEBUG:undefined},
版本:[]
};
以上内容适用于混合应用程序(节点环境)和浏览器

  • 对于“未捕获引用错误:未定义全局”:

    var global=global | |窗口;
    
  • 对于“未捕获引用错误:未定义缓冲区”:

    var Buffer=Buffer | |[];
    
  • 对于“未捕获引用错误:未定义进程”:

    var进程=进程||{
    环境:{调试:未定义}
    }
    
  • 对于“未捕获的TypeError:无法读取未定义的属性'slice'”:

    var进程=进程||{
    环境:{DEBUG:undefined},
    版本:[]
    };
    

将此行添加到
polyfills.ts
应该可以解决节点全局错误

(任意窗口)。全局=窗口


在这种情况下,如果您的目标是Web包中的节点(
target:'node'
),因为您想修复
“无法解析'fs'
”。那么您将得到以下错误
修复:“未捕获引用错误:未定义全局”
按如下操作
节点:{global:true,fs:'empty'}
奖金
:如果出现错误
“未捕获引用错误:未定义导出”。
只需添加
libraryTarget:'umd'
。完整的网页配置代码如下所示

const webpackConfig = {
  node: { global: true, fs: 'empty' }, // Fix: "Uncaught ReferenceError: global is not defined", and "Can't resolve 'fs'".
  output: {
    libraryTarget: 'umd' // Fix: "Uncaught ReferenceError: exports is not defined".
  }
};

module.exports = webpackConfig; // Export all custom Webpack configs.

这里提出了许多解决方案:

我使用了
HttpClient
并意外地选择了默认导入,即
'selenium-webdriver/http'

如果您的app.module.ts从'selenium webdriver/http'导入{HttpClient};

从“@angular/common/http”将其更新为
import{HttpClient};


这解决了我的问题。

将这一行添加到
pollyfills.ts
解决了我的问题(正如@kemalbrinci所说的解决方法)


(如有窗口).global=window;

在我的例子中,
Package.JSON
文件中缺少socket.io条目。请检查它并将其安装到包中。

请小心使用将内联脚本添加到index.html的顶部答案。这将立即解决问题。但是,如果您使用的是SignalR,这将生成此错误:

错误:分析握手响应时出错:TypeError:“instanceof”的右侧不可调用 在HubConnection.push../node_modules/@microsoft/signalr/dist/esm/HubConnection.js.HubConnection.processHandshakeResponse


但是,仅定义全局将起作用,而不会中断信号R。

我不知道这是否有助于任何人理解他们的问题,我只是想我会通知阅读本文的任何人,如果他们在用户端遇到全局未定义错误,请检查您的浏览器和/或设备设置,以查找询问您位置的页面。我刚刚在在chrome浏览器的站点设置旁边,将位置选项从“先问”改为“阻止”。在我访问的下一个页面中,数据表的主要内容显示了此错误消息,当我在chrome站点设置中将位置切换回“先问”并刷新它加载的页面时,没有错误。

检查您的CLI版本:以防出现任何错误ne面临ng 6和AWS cognito的错误,我找到了一个解决方法,如下所述:如何修复此错误Uncaught TypeError:无法读取undefinedIt的属性“slice”,但您能否解释此错误的原因以及如何修复此错误?基本上是新的角度环境,它期望这些全局变量仅在节点中可用如果你把进程值定义为上面的,那么应用程序就是服务器端的应用程序。它不会被认为是Web应用程序。默认情况下,你将收到Paltual.Buffer-Valuy。对于这里的任何人,请检查正在添加的HTTP客户端模块是从@角/通用/HTTP或从SeleWebDeaRe/http.SeleWebDeks/h。ttp也会导致相同的问题。按照angular cli中的建议,添加到polyfills.ts并不能解决我的问题。似乎某些第三方库正在尝试在加载polyfills.ts之前(即,可能在加载angular之前)访问全局。解决此问题的唯一方法是按照上面接受的解决方案修改index.html页面。:-(如果直接将其添加到polyfills.ts不起作用,另一种仍然使用此解决方案的方法是添加新文件(例如,称为global-shim.ts)并在其中添加脚本,然后将新文件导入polyfills.ts。此解决方案在本文中作为导入polyfills.ts文件而被提及,正如@RisingTite为我所述。此外,此问题是在从工作角度11升级到角度12后出现的。许多内容必须在引擎盖下发生更改…一个d推出“全球”肯定是其中之一。我没有使用它,但一定有人在寻找它。太棒了。这对我来说是同一个问题。照你说的做了,它起了作用。非常感谢。这应该是公认的答案!