Giter Site home page Giter Site logo

Comments (3)

rossPatton avatar rossPatton commented on May 2, 2024 1

so, i was able to fix this. here is the solution in case anyone else comes across this problem.

in my case, it was because packages with a / in the name were not being properly aliased. so when react-ab-test was requiring react-dom/server for their server render, it was not being aliased properly

i needed to add the following to my webpack server config (i got this from some other thread, can't remember):

let nodeModules = {}
fs.readdirSync('node_modules').forEach(function (module) {
  if (module !== '.bin') {
    nodeModules[module] = true;
  }
})

const nodeModulesTransform = function(context, request, callback) {
  // search for a '/' indicating a nested module
  const slashIndex = request.indexOf("/");
  let rootModuleName;
  if (slashIndex == -1) {
    rootModuleName = request;
  } else {
    rootModuleName = request.substr(0, slashIndex);
  }

  // Match for root modules that are in our node_modules
  if (nodeModules.hasOwnProperty(rootModuleName)) {
    callback(null, 'commonjs ' + request);
  } else {
    callback();
  }
}

and then in your config object itself add this line:

externals: [nodeModulesTransform],

from preact-render-to-string.

developit avatar developit commented on May 2, 2024

@rossPatton That is usually caused by an alias not working - preact-render-to-string is being passed a React element but it only supports Preact ones. How are you aliasing, and how are you running server-side?

Usually the common problem is that people alias in preact-compat in their webpack config, but then their server-side setup actually imports things directly (ie, not using webpack). The solution is pretty simple, you just need to apply the same aliases from your webpack config to node's module loader itself via module-alias.

from preact-render-to-string.

rossPatton avatar rossPatton commented on May 2, 2024

i am using webpack ProvidePlugin like this:

new webpack.ProvidePlugin({
    React: 'preact-compat',
    ReactDOM: 'preact-compat',
    ReactDOMServer: 'preact-render-to-string',
})

I use webpack for both my server and client builds (i bundle my server file) so I would assume that any aliases I set in webpack would be consistent on both the server and client side

Would this not be the case?

from preact-render-to-string.

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.