简体   繁体   English

Angular 2:参考错误找不到变量required

[英]Angular 2: reference error can't find variable require

I'm trying to include this zookeeper's library in my Angular 2 project. 我正在尝试将此动物园管理员的库包含在我的Angular 2项目中。 I'm following this tutorial , so I created the app, installed the node-zookeeper-client with rpm, and then added ../node_modules/node-zookeeper-client/index.js to my script array in the .angular-cli.json. 我正在按照本教程进行操作 ,因此创建了应用程序,并使用rpm安装了node-zookeeper-client,然后将../node_modules/node-zookeeper-client/index.js添加到了.angular-cli中的脚本数组中以.json。

If I start the application, in the console I see an error like ReferenceError: Can't find variable: require that points to the first line of the index.js file. 如果启动该应用程序,则在控制台中会看到类似ReferenceError: Can't find variable: require的错误ReferenceError: Can't find variable: require指向index.js文件的第一行。

Which is the correct approach to import a third party library like zookeeper? 导入诸如Zookeeper之类的第三方库的正确方法是什么?

Thanks 谢谢

Here's how you should solve it if you are using angular cli. 如果您使用的是角度cli,则应按以下方法解决。 In your 在你的

src/typings.d.ts SRC / typings.d.ts

paste the below code. 粘贴以下代码。 It will work like charm 它将像魅力一样工作

declare var require: any;

Hope this will help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM