RequireJS search for app.app instead of app.js (where app.js is entry point specified in data-main)

女生的网名这么多〃 提交于 2019-12-12 05:56:38

问题


Problem:

I have a trivial demo application which use requireJS. When require.min.js script loads, it tries to load entry-point script. But, the Problem is that instead of localhost:8090/js/app.js it tries to load localhost:8090/js/app.app and fails.

Demo: You can see the whole app at GitHub.

=== Only if you don't like GutHub, here's my code ===

File structure

ProjectRoot
 |-server.js
 |-public/
    |-index.html
    |-js/
       |-app.js
       |-lib/
          |-require.min.js
          |-underscore.js
          |-backbone.js
          |-raphael.js
       |-app/
          |-..

server.js:

var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/public'));
app.listen(8090);

index.html:

<!DOCTYPE html>
<html>
  <body>
  </body>
  <script src="js/lib/require.min.js" data-main="js/app.js"></script>
</html>

app.js:

require.config({
    paths: {
        'jquery': 'lib/jquery',
        'raphael': 'lib/raphael'
    },
    shim: {
        'lib/underscore': {
            exports: '_'
        },
        'lib/backbone': {
            deps: ["lib/underscore", "jquery"],
            exports: 'Backbone'
        }
    }
});

回答1:


There is a problem with your version of require.js included in the app. Use the CDN one and it works.

The version you have in your code does not match the actual .min version on the CDN which means it was modified and includes .app

<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js" data-main="js/app"></script>


来源:https://stackoverflow.com/questions/26816008/requirejs-search-for-app-app-instead-of-app-js-where-app-js-is-entry-point-spec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!