Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Using Alias defined in webpack for client side react rendering but when trying to render on Node server using Express having issue.

I have defined some alias in webpack example

resolve: {
    extensions: ['', '.js', '.jsx', '.cjsx', '.coffee', '.json'],
    alias: {
      pages: path.join(__dirname, 'js/MGPages.js'),
    }
  },

but when require my main app file on node server I am getting below error

Error: Cannot find module 'pages'

Client side alias works fine but how can I solve this problem on node server side. I don't want to change the code of importing file on my react component for client side.

share|improve this question

If you're not webpacking the files that node runs (for example if you're using babel-register instead), then the alias won't apply.

If you want to do something like import pages from 'pages' without having to specify a path you might need to use something like rewrite-modules (which is what React does internally).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.