本文介绍了在Ember CLI中访问第三方库(例如D3)的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的工作方式:

bower install d3 --save

然后添加到 Broccoli.js

app.import('bower_components/d3/d3.js');

然后在我看来,补充:

import d3 from 'bower_components/d3/d3';

并尝试使用它。

这会在启动应用程序时引起问题。在devtools中,我看到此错误:

This causes an issue when launching the app. In devtools I see this error:

Uncaught TypeError: Cannot read property 'length' of undefined  vendor.js:40
Module   vendor.js:52
define   vendor.js:88532
(anonymous function)   vendor.js:88534
(anonymous function)   

所以我想我以错误的方式包含了它。

So I'm guessing that I'm including it the wrong way.

我试图避免向.jshintrc中添加内容,而是使所有导入都显式显示,但到目前为止还算运气。所以我也尝试过:

I'm trying to avoid adding stuff to .jshintrc and making all import explicit instead, but no luck so far. So I tried that too:

不要在模块中导入d3,而是将d3添加到jshint的 predef 。

Don't import d3 in my module, and instead just add d3 to jshint's predef. No luck either, same issue.

你们怎么样了?

谢谢!

推荐答案

我安装了错误的loader.js版本。应该是1.0.1,我有2.1.1。现在一切正常!

I had the wrong loader.js version installed. Should be 1.0.1, and I had 2.1.1. Now everything works!

这篇关于在Ember CLI中访问第三方库(例如D3)的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:43