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

Nextjs14,Use agora-rtc-sdk-ng will report an error: ReferenceError: window is not defined #6

Open
BikeF opened this issue Oct 23, 2024 · 1 comment

Comments

@BikeF
Copy link

BikeF commented Oct 23, 2024

AgoraRTC SDK version

4.20.0

Fail Rate

100%

Link to minimal reproduction

https://github.com/BikeF/test-agora-rtc-sdk-ng.git

Steps to reproduce

  1. npm install
  2. npm run dev
  3. open the page, You will find that the console reports an error:
   ⨯ ReferenceError: window is not defined
    at __webpack_require__ (C:\Users\fanfa\Documents\test-agora-rtc-sdk-ng\.next\server\webpack-runtime.js:33:43)
    at eval (./src/app/page.tsx:8:74)
    at (ssr)/./src/app/page.tsx (C:\Users\fanfa\Documents\test-agora-rtc-sdk-ng\.next\server\app\page.js:129:1)
    at Object.__webpack_require__ [as require] (C:\Users\fanfa\Documents\test-agora-rtc-sdk-ng\.next\server\webpack-runtime.js:33:43)
digest: "942138213"

What is expected?

the module file is AgoraRTC_N-production.js,simple code:

!function (e, t) {
  if ("object" === typeof exports && "undefined" !== typeof module) {
      module.exports = t();
  } else if ("function" === typeof define && define.amd) {

    define(t);
  } else {
    e = "undefined" !== typeof globalThis ? globalThis : e || self;
    e.AgoraRTC = t();
  }
}(this, (function () {

nextjs will exeute t() // from module.exports = t(); in server,so window is not undefined

"agora-rtm" has the same problem.

What is actually happening?

npm run dev will report an error, but it will not affect the use.
npm run build will report an error and cause packaging failure.
I should be able to avoid reporting errors by importing synchronously, but I don't want to do so.

System Info

nextjs14

Any additional comments?

No response

@guoxianzhe
Copy link

@BikeF In nextjs usage, you can check AgoraIO-Extensions/agora-rtc-react#181 (comment)

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

No branches or pull requests

2 participants