gpt4 book ai didi

javascript - 未捕获的语法错误 : Unexpected token < occurring when deploying

转载 作者:太空宇宙 更新时间:2023-11-04 15:25:39 26 4
gpt4 key购买 nike

有一个在后端使用带有节点/express服务器的react路由器的react应用程序,我正在尝试部署到heroku,但它给了我这个错误......

'未捕获的语法错误:意外的标记<'

我相信这是我的 express 服务器中的“catch all”路由,它正在提供index.html..不太确定...这是我的服务器文件的一些内容..

const express = require('express');
const bodyParser = require('body-parser');

const app = express();
const path = require('path');
const bcrypt = require('bcrypt');
const db = require('../database/index.js');
const passport = require('passport');
const helpers = require('./helpers.js');//eslint-disable-line
require('../server/config/passport')(passport);

app.use(express.static(path.join(__dirname, '/../client/dist')));
app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({ extended: true }));
app.use(require('express-session')({
secret: process.env.SESSION_PASSWORD || 'supersecretsecret',
resave: false,
saveUninitialized: false,
}));

app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());

app.post('/', (req, res) => {
res.end();
});

app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, '/../client/dist/index.html'));
});

app.listen(process.env.PORT || 3000, () => {
console.log('listening on port 3000!');
});

这是我的前端 index.jsx 文件..

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import Home from './components/homepage.jsx';
import ArtistRegister from './components/artistregister.jsx';
import VenueRegister from './components/venueregister.jsx';
//import Test from './components/test.jsx';
import reducer from './reducers/index.js';
import { BrowserRouter as Router, Route, Switch } from 'react-router-
dom';//eslint-disable-line

const store = createStore(reducer, applyMiddleware(thunk));

const Base = ({ store }) => (
<Provider store={store}>
<Router>
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/artistregister" component={ArtistRegister}
/>
<Route exact path="/venueregister" component={VenueRegister} />
{/* <Route path="/artist/:username" component={Test} /> */}
</Switch>
</Router>
</Provider>
);

const render = () => {
ReactDOM.render(<Base store={store} />,
document.getElementById('app'));
};

store.subscribe(render);
render();

有什么帮助吗?

最佳答案

我明白了!它使用 babel 正确转译,唯一的问题是部署时,我的bundle.js 在 git-ignore 中。

关于javascript - 未捕获的语法错误 : Unexpected token < occurring when deploying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49523538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com