1

我正在使用 requireJS 加载xchart.js取决于d3.js,并且我不断收到此消息错误Uncaught Error: Script error for: d3

    require({
        paths:{
            'd3': 'vendor/charts/d3.min',
            'charter': 'vendor/charts/xcharts.min'
        }
    },['js/vendor/charts/charter.js'],function(App){
        App.initial_charter();
    });

在 中js/vendor/charts/charter.js,我把

define(['d3','charter'],function(){
        function initial_charter(){
            ...
}return{
            initial_charter: initial_charter
        }
    }
);

所以我尝试了

require(['js/vendor/charts/d3.min.js'],function(){
        require({
            paths:{
                'charter': 'vendor/charts/xcharts.min'
            }
        },['js/vendor/charts/charter.js'],function(App){
            App.initial_charter();
        });
    });

我仍然收到相同的错误消息

更新:我没有改变任何东西,现在在我的控制台中xChart is not defined Rmk:我发现requireJS真的很不稳定,是我还是已知?

4

1 回答 1

1

这个小提琴将加载 d3:

<script>
require = {
    paths: {
        "d3": "https://rawgithub.com/mbostock/d3/v3.3.4/d3"
    },
    shim: {
        "d3": {
            exports: "d3"
        }
    }
};
</script>
<script src="http://requirejs.org/docs/release/2.1.8/comments/require.js"></script>
<script>
require(["d3"], function (d3) {
    console.log.apply(console, arguments);
});
</script>

输出到控制台:

Object {version: "3.3.4", ascending: function, descending: function, min: function, max: function…}
于 2013-09-19T22:22:22.670 回答