2015-07-03 109 views
0

我試圖要求在節點的一些JS文件, Localy - 偉大工程,但在Heroku的我得到這個錯誤 -的Heroku找不到模塊

Error: Cannot find module './routes.js'

我的代碼如下所示:

'use strict'; 

var express = require('express'); 
var app = express(); 

app.set('port', (process.env.PORT || 5000)); 
app.use(express.static(__dirname + '/public')); 

// Application Header 
app.use(function(request, response, next) { 
    response.header('Access-Control-Allow-Origin', '*'); 
    response.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); 
    response.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, X-PINGOTHER'); 

    next(); 
}); 

// views is directory for all template files 
app.set('views', __dirname + '/views'); 
app.set('view engine', 'ejs'); 

    console.log('./routes.js'); 
require('./routes.js')(app); 

app.listen(app.get('port'), function() { 
    console.log('Node app is running on port', app.get('port')); 
}); 

我做錯了什麼? Thanx!

+0

你確定你確實提交了這個文件嗎?因爲代碼對我來說很好。 –

+1

Heroku上存在該文件嗎?第一:'heroku運行bash'然後:'cat routes.js'看。 – hunterloftis

回答

3

您可以嘗試運行一次性動態副本,讓其列出目錄內容 - 這將允許您檢查您的文件是否在您期望的位置。 (Heroku的對這個here的更多信息。)例如:

heroku run 'ls -al'

這將導致Heroku的創造(很簡單),你的應用程序的其他副本,並將它在列出應用程序的目錄中的文件服務器。您可能會發現您的routes.js文件不在您期望的位置。 (?也許它不是住進了GIT)

如果您想閒逛進一步,運行:

heroku run bash

而且你將有一個交互式的bash shell到你的應用程序的副本。從那裏你可以在文件系統中徘徊,嘗試在服務器上手動運行你的應用程序等。

0

你錯過了你在其他地方的__dirname

2

嘗試禁用Heroku構建緩存以重新創建node_modules目錄。

在安裝了Heroku CLI,寫:

$ heroku config:set NODE_MODULES_CACHE=false 
$ git commit -am 'disable_node_modules_cache' --allow-empty 
$ git push heroku master 

如上所述here