【问题标题】:AssertionError: path must be a stringAssertionError:路径必须是字符串
【发布时间】:2017-04-23 09:22:48
【问题描述】:
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 });
        }
    });
});

出现错误:

断言.js:85 抛出新的 assert.AssertionError({ ^ AssertionError:路径必须是字符串 在 Module.require (module.js:482:3) 在需要(内部/module.js:20:19) 在对象。 (/home/historyjagt.portaplay.dk/public_html/app/app.js:4:1) 在 Module._compile (module.js:556:32) 在 Object.Module._extensions..js (module.js:565:10) 在 Module.load (module.js:473:32) 在 tryModuleLoad (module.js:432:12) 在 Function.Module._load (module.js:424:3) 在 Module.runMain (module.js:590:10) 运行时(bootstrap_node.js:394:7)

【问题讨论】:

    标签: node.js require


    【解决方案1】:

    读取错误:

    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,你需要先安装并 require requirejs

    【讨论】:

    • 这个生态系统是弄巧成拙的。这是人为的复杂性。
    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 2023-03-26
    • 2017-04-23
    • 2016-07-25
    相关资源
    最近更新 更多