0

当我尝试构建我的应用程序的生产版本时,我继续收到以下错误。Npm run build 正在公开寻找我的 index.html 文件,但它认为我的公共文件夹在我的根目录中,而它在客户端子文件夹中。

Could not find a required file. Name: index.html Searched in: C:\Users\wharfchillin\wharf-chillin-app\public

我的公用文件夹位于我的应用程序的子文件夹中:

client --->public ------>index.html

我试图以多种方式在我的 server.js 文件中说明这一点:已 更新

const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const path = require('path');

const users = require("./routes/api/users");
const plaid = require("./routes/api/plaid");

const app = express();
const publicPath = path.resolve(__dirname);

// Bodyparser middleware
app.use(
  bodyParser.urlencoded({
    extended: false
  })
);

app.use(bodyParser.json());

app.use(express.static(publicPath));

app.use('*', (req, res) => {
  res.sendFile(path.resolve(publicPath));
});

// production mode
if(process.env.NODE_ENV === 'production') 
  app.use(express.static(path.resolve(publicPath)));  

console.log('test')
console.log(publicPath)

任何建议将不胜感激。

4

1 回答 1

0

您正在使用窗口操作系统,窗口操作系统的路径使用反斜杠,但在您的节点应用程序中,您使用正斜杠定义路径,节点有 api 来处理这个,path.resolve。停止使用 path.join

于 2020-01-24T03:19:37.197 回答