【问题标题】:next-redux-wrapper TypeError: nextCallback is not a function error in wrapper.getServerSidePropsnext-redux-wrapper TypeError: nextCallback is not a function error in wrapper.getServerSideProps
【发布时间】:2021-10-08 19:50:04
【问题描述】:

我在尝试导出 wrapper.getServerSideProps 函数时收到 TypeError: nextCallback is not a function 错误。

我的代码

import App from '../components/App'
import {wrapper} from '../redux/Store';
import {getRooms} from '../redux/actions/RoomAction'

export default function Index() {
  return (
    <App />
  )
}

export const getServerSideProps = wrapper.getServerSideProps(async ({req, store}) => {
     await store.dispatch(getRooms(req))
})

我在导出 getServerSideProps 时遇到错误。

输出

Zia-Sultan:bookit Raymond$ npm run dev

> bookit@0.1.0 dev /Users/Raymond Tucker/projects/next/BOOKIT/bookit
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
event - compiled successfully
event - build page: /
wait  - compiling...
event - compiled successfully
TypeError: nextCallback is not a function
    at /Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:146:46
    at step (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:57:23)
    at Object.next (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:38:53)
    at /Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:32:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:28:12)
    at makeProps (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:135:16)
    at /Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:186:46
    at step (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:57:23)
    at Object.next (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:38:53)
Warning: Invalid DOM property `crossorigin`. Did you mean `crossOrigin`?
    at link
    at head
    at Head (webpack-internal:///./node_modules/next/dist/pages/_document.js:252:5)
    at html
    at Html (webpack-internal:///./node_modules/next/dist/pages/_document.js:241:29)
    at MyDocument (webpack-internal:///./pages/_document.js:17:1)
(node:5114) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'dispatch' of undefined
    at eval (webpack-internal:///./pages/index.js:27:15)
    at /Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:143:52
    at step (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:57:23)
    at Object.next (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:38:53)
    at /Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:32:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:28:12)
    at makeProps (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:135:16)
    at /Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:186:46
    at step (/Users/Raymond Tucker/projects/next/BOOKIT/bookit/node_modules/next-redux-wrapper/lib/index.js:57:23)
(node:5114) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5114) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

【问题讨论】:

    标签: reactjs redux next.js next-redux-wrapper


    【解决方案1】:

    传递给wrapper.getServerSideProps 的函数的签名已在next-redux-wrapper v7.x 中更改。

    替换以下内容。

    export const getServerSideProps = wrapper.getServerSideProps(async ({req, store}) => {
         // Code here
    })
    

    有正确的签名。

    export const getServerSideProps = wrapper.getServerSideProps((store) => async ({ req }) => {
         // Code here
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 2018-11-16
      • 2018-05-17
      相关资源
      最近更新 更多