Ryan Hague
Ryan Hague

Reputation: 51

React - Docker Syntax Error: Unextpected token

I have a react app which starts outside of Docker but not inside.

I'm running a backend Node app which works in Docker, this failing front-end is the issue. From previous threads and questions i'm certain it is not the 'globby' module at fault, it's likely to be my config or installation.

The error:

react-scripts start
/usr/src/app/node_modules/react-dev-utils/node_modules/globby/index.js:49
...taskOptions
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/src/app/node_modules/react-dev-utils/globby.js:10:14)
npm info lifecycle [email protected]~start: Failed to exec start script
npm ERR! Linux 4.19.128-microsoft-standard
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.11.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `react-scripts start`
npm ERR! Exit status 1

My Dockerfile

FROM node:6.11.1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json ./
COPY package-lock.json ./
RUN npm install


COPY . .

EXPOSE 3000
CMD ["npm", "start"]

My package.json

{
  "name": "react-frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "globby": "^11.0.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "^4.0.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

What i've tried:

Upvotes: 0

Views: 1398

Answers (1)

Ryan Hague
Ryan Hague

Reputation: 51

After @vpalmerini pointed out the Node version, I updated to 14.15.4-alpine and ran

docker-compose build
docker-compose up

So now my Dockerfile contains

FROM node:14.15.4-alpine

The app is now running as expected.

Upvotes: 1

Related Questions