Skip to content
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

next 中报错 window is undefined #231

Open
Shunjun opened this issue May 14, 2022 · 6 comments
Open

next 中报错 window is undefined #231

Shunjun opened this issue May 14, 2022 · 6 comments

Comments

@Shunjun
Copy link

Shunjun commented May 14, 2022

APILoader 的 defaultProps 中,从 window 上获取 protocol 会导致在 next ssr 时报 window is undefined。
能否添加一个 window 的判断再获取 protocol
image

@jaywcjlove
Copy link
Member

jaywcjlove commented May 14, 2022

@Shunjun 你可以参考 uiwjs/react-md-editor#52 (comment) 类似的解决方法。

@lhr0909
Copy link

lhr0909 commented Aug 14, 2022

@Shunjun 提供一个可行的NextJS (v12.2) 加载方法:

// components/react-amap-api-loader.ts

import { ComponentType } from 'react';
import { APILoaderConfig } from '@uiw/react-amap-api-loader';
import dynamic from 'next/dynamic';

export const APILoader: ComponentType<APILoaderConfig> = dynamic(
  () => import('@uiw/react-amap-api-loader').then((mod: any) => mod.APILoader),
  { ssr: false },
);

引入的时候注意需要避免引入整个包,不然api-loader的export又会被加载了。

不需要安装 next-remove-imports。目前NextJS默认可能会用swc编译,所以插件可能会不可用。

@yejinghun
Copy link

请问您这个问题解决了吗,我目前也出现了window is undefined.

@yejinghun
Copy link

我按照他的方式,还是会出现这个问题。
#231 (comment)

@yejinghun
Copy link

@jaywcjlove 谢谢,已解决~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants