我正在尝试使用这个WebcamSDK,它可以在React中工作,但不能在NextJS中工作
SDK包含不同的导出,如下所示
//@/component/sdk/WebcamSDK.js
export class Webcam {...}
export class Player {...}
export class Dom {...}
在我的组件中,我有:
//only load Webcam when there's a browser present
const WebcamAssets = dynamic(() => import("@/components/sdk/WebcamSDK"), {
ssr: false
});
...
const Meeting = () => {
useEffect(() => {
...
const { Webcam, Player, Dom } = WebcamAssets;
})
}
上面的代码不能工作,但是当我像这样做纯react导入时,它工作得很好
import { Webcam, Player, Dom } from "path/to/SDK/WebcamSDK"
发布于 2021-10-25 18:23:01
NextJS 'next/dynamic‘模块是为组件制作的。
试试await import()
const Meeting = async () => {
useEffect(() => {
...
const { Webcam, Player, Dom } = await import("@/components/sdk/WebcamSDK");
})
}
https://stackoverflow.com/questions/69716703
复制