注意:对于支持问题,请使用以下渠道之一: stackoverflow或slack
- [x] report a *bug*
- [ ] request a *feature*
socket.io-client 不适用于 @angular/[email protected] rc.3 ,因为它依赖于 node.js 的global
var
(似乎来自[email protected]
,但我找不到维护该版本的人)
见https://github.com/angular/angular-cli/issues/8160
2.0.4
目前也面临这个问题
由于https://github.com/angular/angular-cli/issues/8160现已解决,我们可以关闭此问题吗? 谢谢!
我不这么认为,因为在 angular/cli > 6 他们永久删除了全局。
你能重新开始调查吗? https://github.com/angular/angular-cli/issues/9827
BR,
凯文
在 Angular CLI 可能修复它或可以覆盖 node 命令之前的一种解决方法,然后您可以在tsconfig.app.json
的路径部分添加 socket.io-client slim 文件
"paths": {
....
"socket.io-client": ["../node_modules/socket.io-client/dist/socket.io.slim.js"]
}
即使它目前确实有效,根据https://github.com/angular/angular-cli/issues/9827#issuecomment -369578814,这将是Angular@6
中的一个问题:
“[this] 通常只会造成一种情况,即根本不应该工作的浏览器代码只有在使用非常特定的工具内置时才能工作。这不是一个好情况。”
我确认它在 Angular 6 RC5 中被破坏了。 有人知道解决方法吗?
@ngervasi我们已经做到了,就像我在这里评论的那样: https ://github.com/socketio/socket.io-client/issues/1166#issuecomment -379225639
我试过了:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"paths": {
"socket.io-client": ["../node_modules/socket.io-client/dist/socket.io.slim.js"]
}
}
但它在 Angular 6RC5 中不起作用,我仍然收到错误:
is-buffer.js:4 Uncaught ReferenceError: global is not defined
at Object../node_modules/socket.io-client/node_modules/socket.io-parser/is-buffer.js (is-buffer.js:4)
at __webpack_require__ (bootstrap:74)
at Object../node_modules/socket.io-client/node_modules/socket.io-parser/binary.js (binary.js:8)
at __webpack_require__ (bootstrap:74)
at Object../node_modules/socket.io-client/node_modules/socket.io-parser/index.js (index.js:8)
at __webpack_require__ (bootstrap:74)
at Object../node_modules/socket.io-client/lib/index.js (index.js:7)
at __webpack_require__ (bootstrap:74)
at Object../src/app/_services/websocket.service.ts (log.service.ts:5)
at __webpack_require__ (bootstrap:74)
根据https://github.com/angular/angular-cli/issues/8160#issuecomment -386153833:
添加以下polyfills.ts
应该在Angular@6
中工作:
// Add global to window, assigning the value of window itself.
(window as any).global = window;
在任何情况下,IMO 都不应解决此问题,socket.io-client 应该删除对global
的隐式依赖,或者记录需要 polyfill(任何使用预捆绑源的人,而不仅仅是角用户)
(顺便说一句,最新[email protected]
的来源在哪里?也许我可以帮忙)
哪个是更好的解决方案? https://github.com/socketio/socket.io-client/issues/1166#issuecomment -379225639(添加到tsconfig中的路径)或https://github.com/socketio/socket.io-client/issues/1166 #issuecomment -386195105(分配给全局)?
在使用 Angular CLI 生成的 Angular v6 项目中,这两个选项都适用于我。
@amitport has-binary2
包的来源在这里: https ://github.com/darrachequesne/has-binary
虽然恐怕这不是唯一的发生。
@darrenmothersele不认为只有一个“更好”。 添加“全局”可能会对其他库产生副作用,而添加“超薄”文件可能会对包大小产生负面影响(不一定)
@darrachequesne添加了一个 PR https://github.com/darrachequesne/has-binary/pull/4 (这是一个开始:))
我尝试了这两种解决方案并使用了当前的 Angular 6.0.0 项目,但都没有。 我将路径条目添加到 tsconfig.app.json 和 polyfills.ts 的条目,但在 chrome 中仍然出现相同的错误。
同样在这里,tsconfig 解决方案不适用于 ng cli 6
// 将全局添加到窗口,分配窗口本身的值。
(window as any).global = window;
为我工作
谢谢。
也为我工作! 谢谢!
它也适用于我! 非常感谢 ! :D
你把(window as any).global = window;
放在哪里了?
谢谢。
你好,
就在那儿(在图片上)。
2018-05-17 21:07 GMT+02:00 Alberto Basaglia [email protected] :
你把(window as any)放在哪里了。global = window; ?
谢谢。—
您收到此消息是因为您发表了评论。
直接回复此邮件,在 GitHub 上查看
https://github.com/socketio/socket.io-client/issues/1166#issuecomment-389975067 ,
或使线程静音
https://github.com/notifications/unsubscribe-auth/APZTlGpMwMpnAscifHT2ZQrRUSJqLejCks5tzcp3gaJpZM4QD_kq
.
--
阿诺·杜西-瓦西里夫
Développeur web 全栈 chez Leaf 网站
网站网址: www.leaf-website.esy.es http://www.leaf-website.esy.es
邮件:a.tussy。
电话:07 77 83 29 44
你放哪儿了……
把它放在你的polyfills.ts
(window as any).global = window
在第 63 行和第 70 行之间
2018-05-31 18:31 GMT+02:00 Bibhas Bhattacharya [email protected] :
你放哪儿了……
把它放在你的 polyfills.ts
(window as any).global = window
—
您收到此消息是因为您发表了评论。
直接回复此邮件,在 GitHub 上查看
https://github.com/socketio/socket.io-client/issues/1166#issuecomment-393592879 ,
或使线程静音
https://github.com/notifications/unsubscribe-auth/APZTlPci9GKE3R8lwc1g3qfqWODeXIPiks5t4Br1gaJpZM4QD_kq
.
--
阿诺·杜西-瓦西里夫
Développeur web 全栈 chez Leaf 网站
网站网址: www.leaf-website.esy.es http://www.leaf-website.esy.es
邮件:a.tussy。
电话:07 77 83 29 44
@amitport感谢您提供的解决方法! @AngularTeam ,你们怎么一直打破一切:/你甚至设法让你的人加入 rxjs 团队,突然间,甚至 rxjs 在版本更改时打破了一切……自从第一次稳定发布以来,我一直在跟上 Angular,我很惊讶你的能够在每个版本上打破一切。
@LucasFrecia这是一个 socket.io 问题,而不是 Angular 的问题。 Angular 通过停止在版本 6 中隐藏它做得很好(这被标记为主要的破坏版本)
两周前为https://github.com/webmodules/blob (由 engine.io-parser 使用)添加了另一个拉取请求https://github.com/webmodules/blob/pull/14 。
它没有得到任何响应,这里的任何人都可以合并它吗? @darrachequesne @rauchg @nkzawa?
添加 (window as any).global = window; 到为我工作的 polyfills.ts
@amitport tks。
它工作正常
我将 (window as any).global = window 放在 polyfills.ts 文件中
它不会在 localhost 中给出ReferenceError: global is not defined
,但是如果我尝试使用 http-server 运行生产构建以进行测试,它会给出此错误。
为什么会发生这种情况的任何线索?
超级紧急!
嗨@gupta82anish ,
我将(window as any).global = window;
放在pollyfills.ts
文件中,并在本地主机(开发)中运行该项目,并将其构建用于生产并且没有收到任何错误。
它就像魅力一样。
pollyfills.ts
解决方法中的(window as any).global = window;
似乎在 Angular 核心 6.1.0 中对我有用。 让我们希望socket.io能尽快更新..
(window as any).global = window; 在 pollyfills.ts 中也为我工作!
(window as any).global = window;
这是一个非常巧妙的解决方案。 但这是正确的做事方式吗?
@avinexus7这不是正确的做事方式。 这是socket.io-client
中一个未解决问题的解决方法:使用浏览器中不存在的“全局”对象。
(AFAIK,没有人努力解决这个问题,请参阅忽略:https://github.com/socketio/engine.io-parser/issues/99 和 https://github.com/webmodules/blob/pull /14)
@amitport您能否联系 NPM 支持,以便他们授予您发布blob
包的新版本的权利?
@darrachequesne - 完成,我已经向 NPM 提交了一个请求
(window as any).global = window
或者(window as any) = window
在polyfills.ts
文件中添加上述代码。
根据angular/angular-cli#8160 (comment) :
添加以下
polyfills.ts
应该在Angular@6
中工作:// Add global to window, assigning the value of window itself. (window as any).global = window;
在任何情况下,IMO 都不应解决此问题,socket.io-client 应该删除对
global
的隐式依赖,或者记录需要 polyfill(任何使用预捆绑源的人,而不仅仅是角用户)(顺便说一句,最新
[email protected]
的来源在哪里?也许我可以帮忙)
是的,这对我也有用..谢谢
你放哪儿了……
把它放在你的
polyfills.ts
(window as any).global = window
@bibhas2太好了! 为我工作
现在可能已修复https://github.com/socketio/engine.io-parser/releases/tag/2.1.3已发布(可能需要重新安装不带包锁的 socket.io-client)
不合作
├─引擎。 [email protected]
└─ 插座。 [email protected]
@kartikupadhyay90你可以添加细节吗?
在我的 ReactNative 应用程序中升级到2.2.0
后,我的 socket.io 实例没有收到来自服务器的通知。 不得不降级到2.1.1
@alimek您确定您的错误与此问题有关吗? 是这样,请添加详细信息。 否则,请发布一个新问题
@amitport如果这是上一版本和 2.2.0 之间唯一的一个变化,那么我猜是这样
@alimek改写:如果您的错误与此错误_相同_,请添加详细信息。 否则请打开一个新问题(可能是回归)。
(顺便说一句,我不是这个库的维护者,我只是在评论问题处理的一般工作方式。如果你想解决你的问题,你需要添加可操作的细节并适当地发布)
在我的情况下,似乎 2.2.0 取决于“engine.io-client”:“~3.3.1”,这取决于“engine.io-parser”:“~2.1.1”。 然而,我系统上的 engine.io-parser 似乎是 2.1.2,它仍然包含对“全局”变量的引用。 似乎这已在 2.1.3 中修复,但 npm i 似乎正在拉动 2.1.2
如果我不得不猜测,它似乎可能会恢复到 2.1.2,因为 2.1.3 的最后一次构建失败
https://travis-ci.org/socketio/engine.io-parser
除此之外,我不明白为什么它一直为我拉旧版本
我对 Jest + React + Typescript 有同样的问题,并且无法通过设置(window as any).global = window
来修复它。 我也尝试将代码放入polyfills.ts
文件中,
setupFiles: [
'<rootDir>/tst/polyfills.ts',
'<rootDir>/tst/jest.setup.ts',
],
并且还使用了 Jest 的 defineProperty 方法,但仍然没有运气。
Object.defineProperty((window as any), 'global', {});
copyProps(window, global);
任何人都能够为 Jest 解决这个问题,或者知道我如何才能做到这一点? @amitport有什么想法吗?
谢谢,
@eldem和其他人。 我要关闭它,因为这个线程变得过于笼统地混合了可能不相关的问题。 如果有人发现与 global 和 socket.io-client 有关的问题,请打开一个新问题,其中包含复制说明、控制台中显示的错误、使用的版本等。
使用 Ionic4/Angular7 - 安装 2.1.1 并在\srcpolyfills.ts中添加(window as any).global = window
工作 - 谢谢!
对于我上面的问题:Babel 在转换 socket.io 文件时导致错误。 在 transformIgnore 中添加它对我有用。
transformIgnorePatterns: [
'<rootDir>/node_modules/../lib/socket.io.js'
]
@amitport方法完美地工作
最有用的评论
根据https://github.com/angular/angular-cli/issues/8160#issuecomment -386153833:
添加以下
polyfills.ts
应该在Angular@6
中工作:在任何情况下,IMO 都不应解决此问题,socket.io-client 应该删除对
global
的隐式依赖,或者记录需要 polyfill(任何使用预捆绑源的人,而不仅仅是角用户)(顺便说一句,最新
[email protected]
的来源在哪里?也许我可以帮忙)