node.js - 断言错误: path must be a string

标签 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)

最佳答案

读取错误:

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

关于node.js - 断言错误: path must be a string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034306/

相关文章:

node.js - 如何在 firebase node.js 云函数中推送通知?

Node.js - res.sendFile - 错误 : ENOENT, stat - 即使路径正确

javascript - 在 Knex 更新中从连接表返回数据

php - 为什么找不到我的界面?

javascript - Require ,当模块不存在时如何做回退

node.js - 使用 Node.js 制作可移植在线聊天应用程序是否可行?

node.js - 如何在一个 EC2 实例上运行多个应用程序

javascript - 如何更改这些模块的这些 require 语句以改为使用 import 语句?

javascript - 如何触发所有模块都加载了requireJs

javascript - 主干线 View 未显示