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

Created on 17 Jul 2019  路  2Comments  路  Source: jaredpalmer/razzle

Hi.
After running build script, i cd to the build folder and run server.js with node without any problem. But when i try to move build folder to another directory (ex. IIS website directory) and try to run server.js with node this error pops up.

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?

stale

Most helpful comment

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;
    },
  };

All 2 comments

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;
    },
  };

@majidsajadi salam,
you have to install dependencies on the target machine, so this is why you getting that error.
and what you did with config.externals allows webpack to copy dependencies into final bundle so there is no need to install dependencies on the target machine anymore. (and that's cool)

GG

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krazyjakee picture krazyjakee  路  3Comments

ewolfe picture ewolfe  路  4Comments

alexjoyner picture alexjoyner  路  3Comments

kkarkos picture kkarkos  路  3Comments

JacopKane picture JacopKane  路  3Comments