NextJs / Express TypeError:_typeof不是_app.js中的函数

时间:2019-06-26 20:30:39

标签: reactjs express next.js

我使用next.js在项目上工作了一段时间,但是当需要现场部署时,我开始从express中得到奇怪的举动。我正在使用next.js,表示为后端服务器,并在需要时在客户端浏览器中使用redux持久存储我的一些数据。

pages / _app.jsx

// @flow
import * as React from 'react';
import App, {Container} from 'next/app';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import { getPersistor, getStore } from '../store/configureStore';
import i18n from '../utils/i18n';

type Props = {
    Component: Object,
    pageProps: Object
}

export default class MyApp extends App<Props> {
    render() {
        const { Component, pageProps } = this.props;
        return (
            <Container>
                <I18nextProvider i18n={i18n}>
                    <Provider store={getStore()}>
                        <PersistGate
                            loading={null}
                            persistor={getPersistor()}
                        >
                            <Component {...pageProps} />
                        </PersistGate>
                    </Provider>
                </I18nextProvider>
            </Container>
        );
    }
}

我的商店配置../ store / configureStore.js

import { createStore, applyMiddleware } from 'redux';
import reducer from '../reducers';
import { persistStore } from 'redux-persist';
import { composeWithDevTools } from 'redux-devtools-extension';

let _persistor;
let _store;

// export const history = createBrowserHistory();

export const getStore = (props) => {
    if (_store) {
        return _store;
    }
    const initialState = (props) ? {...props} : {};
    _store = createStore(
        reducer,
        initialState,
        composeWithDevTools(applyMiddleware())
    );

    _persistor = persistStore(_store);

    return _store;
};

export const getPersistor = () => {
    return _persistor;
};

最后是我的server.js文件

const express = require('express');
const next = require('next');
const Router = require('./utils/dynamicRoutes');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = Router.getRequestHandler(app);
const port = process.env.PORT || 3000;

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

app.prepare()
    .then(() => {
        const server = express();
        server.use(bodyParser.json());
        server.use(bodyParser.urlencoded({ extended: true }));

        server.get('*', (req, res) => handle(req, res));

        server.listen(port, (err) => {
            if (err) throw err;
            console.log(`> Ready on http://localhost:${port}`);
        });
    })
    .catch((ex) => {
        console.log(ex);
        console.error(ex.stack);
        process.exit(1);
    });

这是个问题。当我以NODE_ENV=production node server.js的身份启动服务器时,出现此问题

TypeError: _typeof is not a function
    at _interopDefault (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:237:48)
    at Object._interopDefault (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:239:15)
    at call (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:23:31)
    at Object.__webpack_require__ (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:2422:15)
    at call (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:23:31)
    at Module.__webpack_require__ (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:4050:12)
    at call (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:23:31)
    at Object.__webpack_require__ (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:137:18)
    at call (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:23:31)
    at __webpack_require__ (/mnt/sdb1/public/with-jest-flow-app/.next/server/static/GxzjAOI9ZeWUXNEi6WAv6/pages/_app.js:91:18)

我很想知道以前是否有人遇到过这个问题,如果有人能帮助我解决问题,那就太好了

我也在这里问了这个问题-> https://github.com/zeit/next.js/issues/7678

0 个答案:

没有答案