Search code examples
node.jsreactjsdockerbabeljscreate-react-app

Transpile using babel-preset-env without ejecting from create-react-app


I create a react project using create-react-app. And in order to pack it to run elsewhere, i use Docker with this config file:

My Dockerfile

FROM node

COPY package.json .
RUN npm install
COPY . .

RUN npm run build
RUN npm run transpile

CMD PORT=$PORT npm run start:prod

When i run my app inside docker using docker build . -t name_repo, the build stops at step 7/8 (npm run transpile) where i need to transpile the codes using babel (babel-preset-env and babel-preset-react-app) and got this error:

the_Error_here

package.json:

...
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "transpile": "NODE_ENV=production babel src --out-dir transpiled --presets env,react-app",
    "start:prod": "NODE_ENV=production node server.js"
 },
...

Solution

  • I think Node_env is unlikely able to find the present name in the production configuration file . I would suggest please check all the parameters once again and use SET NODE_ENV =production