scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.65k stars 192 forks source link

global in not defined #259

Closed aladdin-add closed 2 years ago

aladdin-add commented 2 years ago

https://github.com/scniro/react-codemirror2/blob/3d490109229e8592772db922e9028c9a1dee3336/index.js#L66

this line will cause error in browsers(no webpack bundled). would it be possible to change to:

(typeof global !== 'undefined' && global['PREVENT_CODEMIRROR_RENDER'] === true)
davidwinter commented 2 years ago

I use this package with Electron, and I was able to workaround it with the following: https://github.com/scniro/react-codemirror2/issues/66#issuecomment-898400845

aladdin-add commented 2 years ago

haha, I used the same workaround 😄.

but better to fix it in the package: https://github.com/scniro/react-codemirror2/pull/260

mhsdesign commented 1 year ago

in esbuild either use:

define: {
    'global': 'window'
}

or a patch see: https://github.com/scniro/react-codemirror2/issues/259#issuecomment-1405396013

marcelgerber commented 1 year ago

Hi @elsigh @scniro, great that this was fixed! Could you release a new version to npm? I'm still running into this issue with the latest published version.

mhsdesign commented 1 year ago

@marcelgerber no they wont ^^

im now using a patch like:


fixes https://github.com/scniro/react-codemirror2/pull/260#issuecomment-1023202972
this bug has been fixed and merged to the source code of react-codemirror2,
but the maintainers said that they won't release it, because they are not using the project anymore.

diff --git a/index.js b/index.js
index d109de477e2b4afa44836ac8da63e75542743919..823a6b014ad15b895dcaf69f88b81f6c575320bd 100644
--- a/index.js
+++ b/index.js
@@ -63,7 +63,7 @@ exports.UnControlled = exports.Controlled = void 0;

 var React = require('react');

-var SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true;
+var SERVER_RENDERED = false;
 var cm;

 if (!SERVER_RENDERED) {
marcelgerber commented 1 year ago

@mhsdesign yes, I'm using a similar patch now (through yarn 3).

it's nice that this is easily possible, but on the other hand it would be even nicer if I didn't have to do that, and could just run the code that's in this repo already, but just doesn't get pushed to npm.

Thank you nonetheless :)