ENOENT:没有这样的文件或目录,stat'/ app / client / build'“

问题描述

我正在使用reactjs和nodejs技术开发一个Web应用程序,此后,我将其部署在HEROKU上,但是当我在Heroku上运行时,出现了一个错误 ENOENT:没有这样的文件或目录,状态为'/ app / client / build'“ 而且我观察到一件事 stat'/ app / client / build',我不知道为什么这条路径不会改变,因为我是reactjs和nodejs的新手。

server.js

    var restify = require("restify");
    var server = restify.createServer();
    
    function respond(req,res,next) {
        res.send('Hello Restify!');
    }
    
    server.get('/hello',respond);
    server.get("/*",restify.plugins.serveStatic({
      directory: __dirname+"/client/build",default: 'index.html',appendRequestPath: false
     })
    );
    var port = process.env.PORT || 5000;
    server.listen(port,function() {
        console.log("Listening on " + port);
    });

解决方法

之所以可能会出错,是因为/client/build目录可能不存在。

  • 确保在执行git add时要包含此文件夹(例如,您可能拥有.gitignore文件,但该目录除外)
  • 一旦推送到heroku,您可以通过以下方式验证服务器上的所有文件:
heroku run bash # should take you to the current dyno's bash
ls              # do you see your client directory?
cd client 
ls              # do you see your build directory?

随时发布您的结果,并告诉我们是否有帮助。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...