plutoless / eEducation

e-education solutions(Agora Reference Design)
184 stars 124 forks source link

ReferenceError: self is not defined #163

Closed iNishant closed 4 years ago

iNishant commented 4 years ago

I have a next.js ts setup instead of the given CRA. I can run the project locally successfully but when I build the project it throws this error

ReferenceError: self is not defined
    at /Users/nishantsingh/Desktop/Ylurn/frontend/website/node_modules/agora-rtm-sdk/index.js:7:61942
    at /Users/nishantsingh/Desktop/Ylurn/frontend/website/node_modules/agora-rtm-sdk/index.js:7:84
    at Object.<anonymous> (/Users/nishantsingh/Desktop/Ylurn/frontend/website/node_modules/agora-rtm-sdk/index.js:7:161)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
Matrixbirds commented 4 years ago

Please provide your minimal reproduce demo here. I will check it ASAP

iNishant commented 4 years ago

@Matrixbirds https://github.com/Ylurn/agora-web-nextjs you can use this. The local setup works but the build for prod is failing. I am also forcing lazy loading so that no code is loaded on server side.

Matrixbirds commented 4 years ago

@Matrixbirds https://github.com/Ylurn/agora-web-nextjs you can use this. The local setup works but the build for prod is failing. I am also forcing lazy loading so that no code is loaded on server side.

Our RTM web SDK only support client-side-rendering solution with AMD module.

Maybe you need try to use script tag to import RTM WebSDK in window object.

iNishant commented 4 years ago

Yup solved it by lazyloading. Somehow the originally lazyloaded component was being built on the server during next.js 's static optimisation