2

I'm transpiling ES6 to ES5.

  1. BabelJS for the NodeJS Express server files and server-side rendering output to a directory build/server/.
  2. Browserify + babelify for the ReactComponents output to a build/client/bundle.js file

When trying to import a React Component from build/client/bundle.js to a build/server/ file the app crashes because I'm importing an untranspiled ReactComponent.

How could I import the ReactComponent without duplicating the code in the server (re-using the code from the client/bundle.js)?

1 Answer 1

2

You have a few solutions:

  • Your server code doesn't need to be pre-compiled. If you run it with babel-node, it will be compiled on-the-fly.

  • You could bundle your server code. I don't know any resource on how to do it with browserify, but here's a very good resource to get started with webpack for your backend.

  • You could build your client code alongside your server code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.