0

I'm compiling my client side using webpack with env, stage-0 and react presets. It was working just fine but now I started working on server-side rendering, so I had to use some es6 and jsx syntax in my server file. I'm compiling it using exact same presets as in webpack, but after running compiled file it throws me an error in one of client files that are being imported inside server file. Here is my packege.json so you could see my command: GitHub (look for "build:s" command)

This is error Im getting after running server file:command line

Am I using babel-cli wrong?

EDIT: I'm in a real pickle here. I tried different approach. I used babel-cli to compile whole client to specified folder and then insode server files import from this folder. But that just gives me bunch of error like "cannot find filename.scss"..... Does anybody know how to solve this problem?

Kreha6
  • 81
  • 8

1 Answers1

0

Babel does not process dependencies for you.

babel ./server/app.js --out-file ./server/app.compiled.js --presets=env,stage-0,react

specifically only compiles what is in app.js. Since app.js imports other stuff, those other files have not been compiled.

Generally you want one folder that has all your original source in it, so I'd do

src/
  server/
  client/

Generally you'd want to do more like

babel ./src --out-dir ./lib --presets=env,stage-0,react

and then execute node ./lib/server/app.js

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
  • Thanks for your answer. I'm gonna check it out ;) – Kreha6 Oct 08 '17 at 15:25
  • The result is the same. I changed my script (pushed it to my repo). Should I compile that way my WHOLE project? Previously I tried to compile my server using separate webpack.config file but it crashed every time I ran "webpack".... – Kreha6 Oct 08 '17 at 15:32
  • Is it wise to make a completly separate compiled copy of my client side just for the server to render it? – Kreha6 Oct 08 '17 at 15:40
  • It's a lot more complicated because you've split things into a "server" and "client" folder. With the command I gave, you're now compiling everything in `server` but the files that imports from `client` won't be processed. I'll expand. – loganfsmyth Oct 08 '17 at 15:47
  • I also tried compiling it in one webpack.config exporting an array just like here [github](https://github.com/Roilan/react-server-boilerplate/blob/master/webpack.config.js) but it crashed as well – Kreha6 Oct 08 '17 at 15:58