File compiled using babel-cli throws an error

110 views Asked by At

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?

1

There are 1 answers

5
loganfsmyth On

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