作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
过去几个小时我一直在努力解决这个问题。我可以通过一个简单的 node.js 应用程序很好地使用react-moveable。当我尝试在 NEXTjs 应用程序中使用相同的模块时,它会抛出错误:TypeError: Cannot read property 'userAgent' of undefined
这是重复的问题: https://codesandbox.io/s/hungry-ramanujan-ttqh3?fontsize=14&hidenavigation=1&theme=dark
据我所知,我似乎正在尝试在服务器端渲染一些本应在客户端的内容。但不确定解决方案是什么......
感谢您的帮助!
最佳答案
这里的问题是该模块尚未准备好 SSR,并且它正在尝试读取 navigator.userAgent
您可以尝试将逻辑移动到另一个组件并使用 next/dynamic 动态导入它,并将 ssr 设置为 false:
import dynamic from 'next/dynamic';
// ...
// other stuff, imports, etc
// ...
const MoveableNoSSR = dynamic(() => import('./MoveableWrapper'), {
ssr: false,
loading: () => <div>Loading Moveable...</div>,
});
关于javascript - 在 NEXTjs 中使用 React-Moveable 时遇到问题 : TypeError: Cannot read property 'userAgent' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59603615/
我是一名优秀的程序员,十分优秀!