升级为React 18后生产错误
我正在尝试更新此下一个JS Starter https://github.com/timlrrrx /tailwind-nextjs-starter-blog
在升级React并反应到18.0.0后,一切都在开发方面运作良好,
但是在试图导航到其他页面时的生产都很好。新页面没有被渲染,并且该错误已在控制台
TypeError: (0 , h.default.startTransition) is not a function
at h.default.createElement.callbacks (main-8f675a98ab9e3b2e.js:1:16469)
at fe (main-8f675a98ab9e3b2e.js:1:16546)
at main-8f675a98ab9e3b2e.js:1:11506
at l (main-8f675a98ab9e3b2e.js:1:93120)
at Generator._invoke (main-8f675a98ab9e3b2e.js:1:92908)
at Generator.S.forEach.e.<computed> [as next] (main-8f675a98ab9e3b2e.js:1:93543)
at M (main-8f675a98ab9e3b2e.js:1:6457)
at i (main-8f675a98ab9e3b2e.js:1:6660)
at main-8f675a98ab9e3b2e.js:1:6719
at new Promise (<anonymous>)
A client-side exception has occurred, see here for more info: https://nextjs.org/docs/messages/client-side-exception-occurred
Uncaught (in promise) Error: Cancel rendering route
at Y (main-8f675a98ab9e3b2e.js:1:14883)
at main-8f675a98ab9e3b2e.js:1:14823
at new Promise (<anonymous>)
at fe (main-8f675a98ab9e3b2e.js:1:14793)
at main-8f675a98ab9e3b2e.js:1:12790
Uncaught (in promise) TypeError: (0 , h.default.startTransition) is not a function
at h.default.createElement.callbacks (main-8f675a98ab9e3b2e.js:1:16469)
at fe (main-8f675a98ab9e3b2e.js:1:16546)
at main-8f675a98ab9e3b2e.js:1:12790
在生产中,它们从react转换为preact DB071EADB60FA9FC4FFB4942661CF/next.config。 JS#L75TOL83
但是,这些问题发生在升级React React PREACT之后出现的不变
以重现以重现
nofollow noreferrer“> repo ,然后在构建网站后,
I am trying to update dependencies in this Next JS Starter https://github.com/timlrx/tailwind-nextjs-starter-blog
After upgrading react and react-dom to 18.0.0 everything was working fine in development
But in production when trying to Navigate to other pages. The new page is not being rendered and this error is being logged in the console
TypeError: (0 , h.default.startTransition) is not a function
at h.default.createElement.callbacks (main-8f675a98ab9e3b2e.js:1:16469)
at fe (main-8f675a98ab9e3b2e.js:1:16546)
at main-8f675a98ab9e3b2e.js:1:11506
at l (main-8f675a98ab9e3b2e.js:1:93120)
at Generator._invoke (main-8f675a98ab9e3b2e.js:1:92908)
at Generator.S.forEach.e.<computed> [as next] (main-8f675a98ab9e3b2e.js:1:93543)
at M (main-8f675a98ab9e3b2e.js:1:6457)
at i (main-8f675a98ab9e3b2e.js:1:6660)
at main-8f675a98ab9e3b2e.js:1:6719
at new Promise (<anonymous>)
A client-side exception has occurred, see here for more info: https://nextjs.org/docs/messages/client-side-exception-occurred
Uncaught (in promise) Error: Cancel rendering route
at Y (main-8f675a98ab9e3b2e.js:1:14883)
at main-8f675a98ab9e3b2e.js:1:14823
at new Promise (<anonymous>)
at fe (main-8f675a98ab9e3b2e.js:1:14793)
at main-8f675a98ab9e3b2e.js:1:12790
Uncaught (in promise) TypeError: (0 , h.default.startTransition) is not a function
at h.default.createElement.callbacks (main-8f675a98ab9e3b2e.js:1:16469)
at fe (main-8f675a98ab9e3b2e.js:1:16546)
at main-8f675a98ab9e3b2e.js:1:12790
In production they switch from react to preact https://github.com/timlrx/tailwind-nextjs-starter-blog/blob/41839607af9db071eadb60fa9fc4ffb4942661cf/next.config.js#L75toL83
But the issues occurs after upgrading react only preact is left unchanged
To reproduce just clone the repo and change react and react-dom version to 18.0.0
After building your site when navigating you will see the issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
React V18中的新钩子尚未解决。您需要恢复新挂钩的使用。
您可以跟踪以下问题,这些问题将挂钩添加到提前: https://github.com/preactjss /preact/pull/3510
侧面注意:您应该真正坚持一个lib(对dev&amp; prod均可进行反应或反应)。基于环境之间的切换使您非常容易遇到您不会期望的小矛盾之处。您的开发环境应该始终是匹配生产环境的最佳效果,因此,如果这意味着要使用preact,则也应该在开发中使用preact。
这是一种非常糟糕的做法,在某种程度上在NextJS用户中受欢迎。
Preact doesn't yet shim the new hooks in React v18. You'll need to revert usage of the new hooks.
You can track the following issue which adds the hooks to Preact: https://github.com/preactjs/preact/pull/3510
Side note: You should really stick to one lib (Preact or React for both dev & prod). Switching between them based on the environment makes you extremely prone to running into small inconsistencies that you won't expect. Your dev environment should always be a best-effort to match your production environment, so if that means using Preact, you should use Preact in dev too.
This is a really bad practice that's somehow gotten popular with NextJS users.
在升级到
React> React
18之后,您对您也有同样的问题,我也使用该模板。经过一天的试图找到解决方案的解决方案,并且已关闭了被接受的答案中提到的PR,我决定从
React> React
preaeAct
中删除切换。在生产中(即,使用react
dev和prod),它解决了问题,并且该网站正常工作。这是这样做的方法:
next.config.js
react> react
preactect
in for in prod in prod参考
Having the same problem with you after upgrading to
react
18 as I'm using that template too.After a day of trying to find a solution w/o having any possible workaround and the PR mentioned in the accepted answer has been closed I decided to remove switching from
react
topreact
in production (i.e., usingreact
for both dev and prod) and it solved the issue and the site worked fine.Here is how to do that:
next.config.js
react
topreact
in prodReference from my repo.