catamphetamine / universal-webpack

Isomorphic Webpack: both on client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running into issues with modules not resolving on server script

greyvugrin opened this issue · comments

Errors are as follows:

Module not found: Error: Cannot resolve module 'webpack/hot/dev-server' in /opt
resolve module webpack/hot/dev-server in /opt
  looking for modules in /node_modules
    /node_modules/webpack doesn't exist (module as directory)
[/node_modules/webpack]
 @ multi app
multi vendor
Module not found: Error: Cannot resolve module 'webpack/hot/dev-server' in /opt
resolve module webpack/hot/dev-server in /opt
  looking for modules in /node_modules
    /node_modules/webpack doesn't exist (module as directory)
[/node_modules/webpack]
 @ multi vendor
multi vendor
Module not found: Error: Cannot resolve module 'react' in /opt...

And

ERROR in Entry module not found: Error: Cannot resolve directory './app/server' in /opt
resolve directory ./app/server in /opt
  /opt/app/server/package.json doesn't exist (directory description file)
  /opt/app/server doesn't exist (directory default file)

It seems like the issues are coming from the requires in my app. In the repo description you mentioned that this project doesn't hack server side requires, so does that mean that these issues should be best solved with the isomorphic tools version?

Thanks in advance!

"Module not found: " is a Webpack error, not Node.js.
So it's not server-side specific.
I guess your webpack configuration has a bug somewhere.

Thanks for pointing me in the right direction, turns out all the packages not resolving were fixed by adding

resolveLoader: {
  root: path.join(__dirname, 'node_modules')
}

to my webpack config.

After fixing those errors I stumbled on one more, once webpack finishes the server bundle and tries to run it I get:

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)

Have you ever seen anything like this before?
I've heard of people having to support node requires by excluding node modules in webpack. In your repo, https://github.com/halt-hammerzeit/webpack-react-redux-isomorphic-render-example, I don't see any active code attempting that, but it seems to work fine anyway.

Cannot find module 'express' means that you don't have express installed, as simple as that.

I should have specified, but the package is already installed.

Then the compiled server-side bundle can't reach that package on disk.