Webpack tidbit [1]

When a project is build using webpack, dynamically requiring a JS module from another JS module may not work.

For example:

If we build this file using webpack and run it, on line 21, the require function will fail with an error saying it could not find the module specified by the `filePath`.

This happens because webpack seems to overwrite the require function in the output file. The webpack `require` function looks for a module with the name of the file in the list of modules built along with source file. In this case, since we did not build the generators folder (or did not include all files from the generators folder) into the source file, it wont be possible to use require on these files. You will however be able to use “fs.readFile”.

Background story: I just started learning how to build isomorphic web apps using Node and React.