gpt4 book ai didi

javascript - Angular 2 : reference error can't find variable require

转载 作者:行者123 更新时间:2023-12-03 03:00:33 24 4
gpt4 key购买 nike

我正在尝试包含 this我的 Angular 2 项目中的 Zookeeper 库。我正在关注this tutorial ,所以我创建了应用程序,使用 rpm 安装了 node-zookeeper-client,然后将 ../node_modules/node-zookeeper-client/index.js 添加到 .angular- 中的脚本数组中cli.json。

如果我启动应用程序,在控制台中我会看到类似 ReferenceError: Can't find variable: require 的错误,该错误指向 index.js 文件的第一行。

导入像zookeeper这样的第三方库的正确方法是什么?

谢谢

最佳答案

如果您使用 Angular cli,则应如何解决该问题。在你的

src/typings.d.ts

粘贴以下代码。它会像魅力一样发挥作用

declare var require: any;

希望这会有所帮助

关于javascript - Angular 2 : reference error can't find variable require,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47412342/

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