Search code examples
javascriptnode.jsreactjsdeploymentrazzle

Razzle - React not found Error on running server.js in build folder


I used Razzle for a server side rendered react app.

Now its time to deploy the application on server. I use IIS as web server. But when i move the build folder to another directory and run node server on it there are errors that i cant find the modules i used in my app, like react.

internal/modules/cjs/loader.js:638
    throw err;
    ^
Error: Cannot find module 'react'
...

Should i move the node_modules folder with build folder? or am i doing something wrong?


Solution

  • Since nobody answered my question. I share what i found out.

    Razzle use webpack-node-externals to exclude node_modules on build. (i dont know why)

    A simple change in razzle.config.js would fix this.

    module.exports = {
        modify: (config, { target, dev }, webpack) => {
          if (target === "node") {
            config.externals = []    
          }
          return config;
        },
      };