bonafideduck / react-highlight-within-textarea

React component for highlighting bits of text within a textarea
93 stars 13 forks source link

Getting Uncaught ReferenceError: global is not defined #190

Open royalsanga24 opened 1 week ago

royalsanga24 commented 1 week ago

Tried using this example: https://github.com/bonafideduck/react-highlight-within-textarea?tab=readme-ov-file#usage

But getting an error in console and app not loading as well. Am I doing something wrong? The error: Screenshot 2024-09-12 at 1 23 34 PM

bonafideduck commented 1 week ago

Are you including draftjs in yourpackage.json?

royalsanga24 commented 1 week ago

Yes, "react-highlight-within-textarea": "3.2.1", "draft-js": "^0.11.7",

These are the installed dependencies. Do I need to add any other dependency as well?

royalsanga24 commented 1 week ago

@bonafideduck I found something. The above error occurs when we create a react app using vite. I tried creating a react app using create-react-app and it works.

Not sure why this is happening with vite. Any ideas?

Using "vite": "^5.4.1"

Edit: For anyone looking to solve this, https://github.com/vitejs/vite/discussions/5912#discussioncomment-2908994 this fixed it

bonafideduck commented 1 week ago

This seems to be in draftjs which has been abandoned. I have ideas on replacing it, but no time lately.

global is a node thing (ref). Perhaps webpack would define it.

Does adding this to your App.js help?

window.global = globalThis;