I want to include angular JS Using require so I am using below code
var ang = require('angular');
But It displays error
ReferenceError: window is not defined
I Know window object not defined in node console but help me how to avoid this error ?
I hope my question understandable.
This is because, Next. js is server-side rendered, and it runs the component code in the server, sends the HTML to the browser, and the HTML gets hydrated in the browser.
window is not defined on the server, so you can't use it during the render of a component being SSR'd. During a component render, use the useIsSsr hook. If outside of a component render, then directly check typeof window === "undefined" to see if you're on the server or the browser.
The global object provides variables and functions that are available anywhere. By default, those that are built into the language or the environment. In a browser it is named window , for Node. js it is global , for other environments it may have another name.
The window
object is only defined in the browser, and isn't defined within Node.js (which uses process
instead).
The reason you're getting this error is because you're trying to require a module (angular.js) that was intended to be used with the DOM from a browser, and not within the Node.js environment.
If you want to include angular in your HTML code, include it like you would any other JS file using a tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With