Closed rajamarko closed 2 months ago
I previously used ams js sdk and web player with next js. You need to disable SSR for it to work. Example:
Add
"use client";
line to the head of your component where you import WebRTCAdaptor or Web Player
When you are importing the component where you are using WebRTCAdaptor or Web Player on a next.js page or component, import it with dynamic and disable ssr
import dynamic from "next/dynamic";
const VideoPlayerComponent = dynamic(
() => import("../videoplayer/VideoPlayerComponent"),
{
ssr: false,
}
);
Please try like this. If it doesnt work let me know.
Thank you @lastpeony this actually works :)
dynamic(
() => import("../videoplayer/VideoPlayerComponent"),
{
ssr: false,
}
);
But the error I posted above indicates an import mismatch inside @antmedia/webrtc_adaptor package, and dynamic import only masks the problem.
I did some digging and if you go to package: \node_modules\@antmedia\webrtc_adaptor\package.json and remove line 7: - "type": "module"
Then the error from above is removed, you will still get an error where "window is not defined", but this is "normal" next js SSR stuff. (and you still have to use, 'use client' or dynamic )
@rajamarko happy to hear that it works Are there anything else you expect from AMS side or i will close the issue.
Short description
Next js (page router) app crashes after importing @antmedia/webrtc_adaptor
Environment
Steps to reproduce
Logs
...ReferenceError: require is not defined in ES module scope, you can use import instead This file is being treated as an ES module because it has a '.js' file extension and '...path\test-ant-media\node_modules\@antmedia\webrtc_adaptor\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///...path/test-ant-media/node_modules/@antmedia/webrtc_adaptor/dist/index.js:3:22 at ModuleJob.run (node:internal/modules/esm/module_job:218:25) at async ModuleLoader.import (node:internal/modules/esm/loader:329:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)