next-redux-wrapper TypeError: nextCallback is not a function error in wrapper.getServerSideProps [英] next-redux-wrapper TypeError: nextCallback is not a function error in wrapper.getServerSideProps
本文介绍了next-redux-wrapper TypeError: nextCallback is not a function error in wrapper.getServerSideProps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试导出 wrapper.getServerSideProps
函数时,出现 TypeError: nextCallback is not a function
错误.
I'm getting TypeError: nextCallback is not a function
error when I try to export wrapper.getServerSideProps
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.
推荐答案
传递给 wrapper.getServerSideProps
的函数的签名在 next-redux-wrapper
v7.x.
The signature for the function passed to wrapper.getServerSideProps
has changed in 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
})
这篇关于next-redux-wrapper TypeError: nextCallback is not a function error in wrapper.getServerSideProps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文