简体   繁体   中英

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

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'
        }
    }
});

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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