Skip to content

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

@BikeF

Description

@BikeF

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions