Giter Site home page Giter Site logo

Comments (4)

richardscarrott avatar richardscarrott commented on June 8, 2024

@cdoublev looks like React is behaving differently when bundled with Webpack target 'node' vs running directly in Node -- if you add 'react' to your externals 'keep' array in your Webpack config it fixes it.

Pretty certain it's unrelated to require-from-string as last time I looked that works exactly the same way as require but without the restriction of reading from disk...

from webpack-hot-server-middleware.

richardscarrott avatar richardscarrott commented on June 8, 2024

I've got a hunch it's something to do with multiple instances of React and context -- although I'd have thought marking it as external would ensure there is just a single instance.

from webpack-hot-server-middleware.

cdoublev avatar cdoublev commented on June 8, 2024

Thank you for the feed back. It led me to the right place, I think.

The logic below for Context differs depending on PROD or DEV mode. In DEV mode, we create a separate object for Context.Consumer that acts like a proxy to Context. This proxy object adds unnecessary code in PROD so we use the old behaviour (Context.Consumer references Context) to reduce size and overhead. The separate object references context via a property called "_context", which also gives us the ability to check in DEV mode if this property exists or not and warn if it does not.

I'm still wrapping my head for what it entirely means, but in the meantime, using React directly from NodeJS is a working and totally acceptable solution. Thank you a lot!

Edit: ok, this is what you actually mean by "React is behaving differently when bundled with Webpack target 'node'", ie. the PROD package is used even if we run NODE_ENV=development node server/index.js.

from webpack-hot-server-middleware.

cdoublev avatar cdoublev commented on June 8, 2024

This was an error on my Webpack config. I had mode: 'production' set for the server build, which was setting NODE_ENV to production. Thank you again! :)

from webpack-hot-server-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.