-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'document is not defined' in next.js #130
Comments
@haiifeng 需要安装 |
|
@haiifeng Upgrade |
我升级到1.18.7了。但是还是报这个错。ReferenceError: document is not defined ReferenceError: document is not defined |
@haiifeng Upgrade 你可以提供一个可以运行的示例我测试一哈。 |
老哥,提了一个PR,兼容了下SSR的情况。 项目刚开始开发,暂时没示例,辛苦老哥跑一下试试:https://www.nextjs.cn/docs/getting-started,跑好demo直接引入地图就行 |
#133 Upgrade |
https://codesandbox.io/s/react-baidu-map-for-nextjs-qsy5t?file=/pages/index.js import Link from "next/link";
import { Map, APILoader } from '@uiw/react-baidu-map'
import { useEffect, useState } from "react";
export default function IndexPage() {
const [maps, setMaps] = useState()
useEffect(() => {
setMaps(
<APILoader akay="GTrnXa5hwXGwgQnTBG28SHBubErMKm3f">
<Map />
</APILoader>
)
}, [])
return (
<div>
Hello World.{" "}
<Link href="/about">
<a>About</a>
</Link>
<div style={{ width: '100%', height: '300px' }}>
{maps}
</div>
</div>
);
} |
在nextjs项目中使用该组件,会报'document is not defined' in '/@uiw/react-baidu-map/lib/cjs/utils'。
加了'if (process.browser)'条件后,报' _interopRequireDefault is not a function' in 's@uiw\react-baidu-map\lib\cjs\APILoader\index.js'
所以现在有点不知所措了,大佬有什么解决办法来兼容ssr后端渲染的不?
The text was updated successfully, but these errors were encountered: