catamphetamine / universal-webpack

Isomorphic Webpack: both on client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module resolve issue in server bundle

osenvosem opened this issue · comments

I have shared folders at many levels in my universal React app:

  resolve: {
    extensions: ['.js', '.jsx', '.json'],
    modules: ['node_modules', 'shared']
  },

When I start server bundle I get:

Error: Cannot find module 'services/api'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Volumes/Data/development/dev/ssr/server/server.bundle.js:1648:18)
    at __webpack_require__ (/Volumes/Data/development/dev/ssr/server/server.bundle.js:21:30)
    at Object.module.exports.Object.defineProperty.value (/Volumes/Data/development/dev/ssr/server/server.bundle.js:905:12)
    at __webpack_require__ (/Volumes/Data/development/dev/ssr/server/server.bundle.js:21:30)
    at Object.module.exports.Object.defineProperty.value (/Volumes/Data/development/dev/ssr/server/server.bundle.js:161:14)
    at __webpack_require__ (/Volumes/Data/development/dev/ssr/server/server.bundle.js:21:30)
    at Object.module.exports.Object.defineProperty.value (/Volumes/Data/development/dev/ssr/server/server.bundle.js:1273:13)
    at __webpack_require__ (/Volumes/Data/development/dev/ssr/server/server.bundle.js:21:30)
    at Object.<anonymous> (/Volumes/Data/development/dev/ssr/server/server.bundle.js:575:14)
    at __webpack_require__ (/Volumes/Data/development/dev/ssr/server/server.bundle.js:21:30)
    at Object.<anonymous> (/Volumes/Data/development/dev/ssr/server/server.bundle.js:1722:17)
    at __webpack_require__ (/Volumes/Data/development/dev/ssr/server/server.bundle.js:21:30)

@halt-hammerzeit do you plan adding the support of this feature?

No I don't.
I could possibly accept a PR though (if this feature can even be implemented).

I have the same issue. Adding the alias as the readme suggested didn't work. What else could be missing?

  resolve: {
    extensions: [ ".js", ".jsx", ".json", ".scss" ],
    alias: {
      actions:    path.resolve(__dirname, '../front/app/actions'),
      ...
    }
  },

Somehow webpack think it is a external package:
at Object.<anonymous> (.../build/server/webpack:/external "actions_responsive":1:1)

Adding "actions" to exclude_from_externals setting didn't help...

You can print the resulting webpack configuration JSON to console and examine it to see if there are any bugs.

Ok, sorry about the alias issue, it does work but using import x from "<alias name>/module"

On my setup we have global modules defined in webpack resolve.modules so we do imports like import x from module assuming "module" is inside any folder we put in there.

So this suggestion about using alias instead of modules (https://github.com/halt-hammerzeit/universal-webpack#resolvemoduledirectories) is because resolve.modules simple doesn't work so we have to change our application code?

Thanks in advance

I don't know if Webpack aliases are supposed to work in import x from module cases. I'd suppose they should.

You can try to fork the repo and implement support for resolve.modules yourself if you want (but there's no guarantee it would get merged)