【问题标题】:ENOENT: no such file or directory, stat '/app/client/build'"ENOENT:没有这样的文件或目录,stat '/app/client/build'"
【发布时间】:2020-12-05 10:07:14
【问题描述】:

我正在使用 reactjs 和 nodejs 技术开发一个 Web 应用程序,之后,我将它部署在 HEROKU 上,但是当我在 Heroku 上运行时,它给了我一个错误 ENOENT:没有这样的文件或目录,stat '/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);
    });

【问题讨论】:

  • 文件在/app/client/build路径下吗?

标签: node.js reactjs heroku restify


【解决方案1】:

这可能出错的原因是/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?

【讨论】:

    猜你喜欢
    • 2021-09-22
    • 2021-04-04
    • 2017-01-24
    • 1970-01-01
    • 2019-05-31
    • 2021-04-26
    • 1970-01-01
    • 2022-01-26
    • 2019-08-22
    相关资源
    最近更新 更多