AssertionError:path必须是一个字符串

时间:2016-12-08 07:46:21

标签: node.js require

require([ 
    'common',

    // Libs
    'jquery', 
    'parse',
    'i18n',

    // Modules
    'modules/login/controllers/login',
    'modules/page/controllers/page',

    // Styles
    'css!../assets/css/bootstrap.min.css',
    'css!../assets/css/tablesorter-bootstrap-theme.css',
    'css!../assets/css/common.css',
],

function(common, $, Parse, i18n, Login, Page) {

    // Defining the application router, you can attach sub routers here.
    var Router = Parse.Router.extend({
        routes : {
            '' : 'index'
        },

        index : function() {
            var currentUser = Parse.User.current(),
                view, container;

            // Load either login screen or navigation bar, 
            // depending on the login state of current user.
            if(currentUser){
                view = new Page.Views.Navbar();
                container = '#navbar';
            } else {
                view = new Login.Views.Login();
                container = '#main';
                $('#navbar').html(null); // Remove the navbar
            }
            view.render(function(el) {
                $(container).html(el);
            });
        }
    });

    $(function() {
        // Initialize internationalization
        i18n.init({
            saveMissing: true,
            debug: true,
            //preload: ['dk', 'en'],
            getAsync: false
        });

        Parse.initialize('****','****');

        // Initialize the Router
        var router = new Router();
        Parse.history.start({ pushState: false });
    });


    $(document).on( 'click', 'a:not([data-bypass])', function(evt) {
        // Get the anchor href and protcol
        var href = $(this).attr('href');
        var protocol = this.protocol + '//';

        if (href && href.slice(0, protocol.length) !== protocol && href.indexOf('javascript:') !== 0) {
            evt.preventDefault();
            Parse.history.navigate(href, { trigger: true });
        }
    });
});

收到错误:

assert.js:85
  throw new assert.AssertionError({
  ^
AssertionError: path must be a string
    at Module.require (module.js:482:3)
    at require (internal/module.js:20:19)
    at Object. (/home/historiejagt.portaplay.dk/public_html/app/app.js:4:1)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)

1 个答案:

答案 0 :(得分:4)

阅读错误:

AssertionError: path must be a string
    at Module.require (module.js:482:3)
    at require (internal/module.js:20:19)
    at Object. (/home/historiejagt.portaplay.dk/public_html/app/app.js:4:1)

看看你的代码:

 require([

数组不是字符串。

我认为我已经解决了发生了什么事情,但如果有人更具体地说明他们从哪里复制粘贴代码,那会更容易。

函数require(array, callback)RequireJS的一部分。 NodeJS没有使用它,而是使用require(string)。如果你想在NodeJS中使用RequireJS,你需要首先安装并需要requirejs