reactjs / React.NET

.NET library for JSX compilation and server-side rendering of React components
https://reactjs.net/
MIT License
2.3k stars 937 forks source link

Add existing css on jsx throw exception - ReferenceError: 'document' is not defined #1231

Closed BhagiLimbu closed 3 years ago

BhagiLimbu commented 3 years ago

Thanks for filing a bug! To save time, if you're having trouble using the library, please check off the items you have tried. If you are just asking a question, skip right to the bottom.

Please verify these steps before filing an issue, and check them off as you go

I'm using these library versions:

Runtime environment:

Steps to reproduce


(Describe your issue here) When I run application that has imported css file on jsx file. It throws an exception.

Steps - 1) Add - import "./test-demo.css"; on home.jsx file 2) Build npm (npm run build) 3) Run application

Results: React.Exceptions.ReactScriptLoadException: Error while loading "/dist/vendor.50cbf625.js": ReferenceError: 'document' is not defined ---> JavaScriptEngineSwitcher.Core.JsRuntimeException: ReferenceError: 'document' is not defined

I am new to ReactJs. Appreciate, if you could suggest sorting out the issue with the CSS file. Thank you.

KlochkovIUS commented 3 years ago

Hello!

Do you find a workaround?

BhagiLimbu commented 3 years ago

@KlochkovIUS ,

I solved it by using a styled component instead of reference css on the file. Here's a link of CSS-in-JS (https://reactjs.net/features/css-in-js.html)

I hope this helps you.

danielHalan commented 3 years ago

Have same issue, where "import 'some.css" causes the described error.

Would like to have reference to external (s)css, and not mixing styles in the component. suggest to re-open the ticket.

Daniel15 commented 3 years ago

@danielHalan - You can't use document with server-side rendering because document is part of the DOM, which doesn't exist server-side.

danielHalan commented 3 years ago

@Daniel15 Noted that disabling server-side rendering actually removes the error, while css is not included/applied...

Inspecting the added code for CSS loader and for the css file, I cant see any reference to document.. is there any way to include external css files to the bundle files?

danielHalan commented 3 years ago

Update: Was a bit quick to reply, Disabling server-side didn't remove the error. (had commented away the import)