带有角度和jquery的require.js会导致脚本错误

时间:2016-09-11 13:18:22

标签: requirejs

美好的一天。我是require.js的初学者。

我的html中有下一个脚本和css(位于同一文件夹中的style.css和script.js,其中html是):

<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel='stylesheet' href='style.css'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.27/angular.js"></script>
<script src="https://cdn.bootcss.com/angular-ui-router/0.2.18/angular-ui-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.27/angular-animate.js"></script>
<script src="script.js"></script>

我将require.js添加为第一个脚本:

<script data-main="main" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.1/require.js"></script>

并添加main.js,写在那里:

requirejs.config({
    baseUrl:"",
    paths: {            
    "jquery":"https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js",
        "bootstrap":"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
    (etc etc)    
    }
});

define(["jquery"], function() {

});

define(["bootstrap"], function() {

});
etc

我得到了

Error: Script error for "jquery", needed by: main
http://requirejs.org/docs/errors.html#scripterror

我需要修理什么?

1 个答案:

答案 0 :(得分:0)

来自RequireJS文档:

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: 'js/lib',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //**never includes a ".js" extension since
    //the paths config could be for a directory**.
    paths: {
        app: '../app'
    }
});

路径不应以“.js”结尾。通过从路径中删除“.js”,您的代码应该可以正常工作。