创建应用程序做出反应生产建设成功,但有错误产生的代码

问题描述 投票:1回答:1

我有一个创建反应的应用程序内作出反应的应用程序我一直在使用的WebPack-dev的服务器发展,一切工作也正在开发中。

然而,当我建立生产,输出生成不工作,并具有以下控制台错误:

Uncaught SyntaxError: Unexpected token < :4001/static/js/1.33f1f515.chunk.js/:1
Uncaught SyntaxError: Unexpected token < :4001/static/js/main.625fef55.chunk.js/:1
Uncaught SyntaxError: Unexpected token < manifest.json:1 Manifest: Line: 1, column: 1, Unexpected token.
reactjs webpack create-react-app webpack-4
1个回答
0
投票

您是否使用快递(的NodeJS)服务器在生产环境中?

如果是,那么查看静态文件服务的配置。问题是/manifest.json/static/js/main.625fef55.chunk.js/等是index.html返回,而不是清单或JS文件。

这里是我的示例服务器文件 -

const express = require('express');
const path = require('path');
const app = express();

app.use('/', express.static(path.join(__dirname, '../build')));

app.use(function(req, res, next) {
  //console.log(req.originalUrl);
  next();
});

// to check if server is running
app.get('/ping', (req, res) => {
  res.json({
    success: true,
    message: 'pong'
  })
});

app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname, '../build', 'index.html'));
});

module.exports = app;
© www.soinside.com 2019 - 2024. All rights reserved.