【问题标题】:Requiring files on Heroku在 Heroku 上需要文件
【发布时间】:2012-02-01 04:02:37
【问题描述】:

我在将 nodejs 应用程序部署到 Heroku 时遇到问题。 Git 推送并正确构建和部署,但随后崩溃。

崩溃似乎是由于对我自己的非模块文件使用 require 引起的,例如: var bla = require("./bla.js");

从“heroku run bash”中,当我对自己的一个文件执行要求时,我还可以看到奇怪的行为,它会在几分钟内将垃圾喷到终端中,而不是预期的结果。

相同的应用程序在本地和其他服务器上运行良好。

确切的错误信息总是有用的:

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick

我制作了一个简单的测试文件来演示这个问题:

var express = require("express"),
    log = require("./analytics/log.js").log; 
    // if I comment out this line it works, the file does exist within heroku 
    // and works outside of heroku, but it seems any of my own files being 
    // require'd will trigger the crash

var app = module.exports = express.createServer();

app.configure(function(){
    app.use(express.static(__dirname + "/public"));
    app.use(express.methodOverride());
    app.use(app.router);
});

app.all("*", function(request, response) {
   response.end("bla");
});

app.listen(process.env.PORT || 3000);

【问题讨论】:

  • bla 是文件夹还是模块?你提交了文件夹 bla 吗?
  • 这只是一个 JavaScript 文件,尽管该问题也会影响文件夹中的文件。这些文件确实存在,它们可以从 heroku bash 中看到 + 我可以 cat 它们并查看它们是否符合预期。要求任何已安装的模块都可以正常工作。
  • 你介意把我指向heroku repo
  • 这不是一个公开的回购,但我会添加一个例子。
  • 我想我发现了更多的问题。 nodejs 项目及其文件是在 linux 中创建的,但我正在从 OS X 推送到 heroku。我在 OS X 中创建的文件确实“需要”正确。

标签: node.js heroku


【解决方案1】:

问题似乎是在 Linux 上创建的文件是“text/x-c”而不是“text/plain”。

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2018-12-21
    • 2015-10-19
    • 1970-01-01
    • 2016-02-10
    相关资源
    最近更新 更多