Docker Community Forums

Share and learn in the Docker community.

Docker container shutting down with logs "SyntaxError: Unexpected token '<'"

So I’m new with docker and I’m running a very simple react app just so I can test my grounds and learn the fundamentals. BUT I’ve been stuck on this error for 2 days now.

My docker container exits after run immediately with a syntax error in index.js

Here is an overview :

  • *I used create react app and simply added some components
  • *Built a docker file this way (this is only the first step of the tutorial I’m following)

FROM node:15
COPY package.json .
RUN npm install npm
COPY ./src ./
CMD [“node”, “index.js”]

  • *I run my image with this command docker build -t node-app-image .

  • *I run my container with this command docker run -d -p 3000:3000 --name node-app node-app-image
    *This is my package.json :

  • THIS IS THE error :sweat: with docker logs :
    SyntaxError: Unexpected token ‘<’
    at Loader.moduleStrategy (node:internal/modules/esm/translators:147:18)
    at async link (node:internal/modules/esm/module_job:48:21)

  • *PS: I’m using ubuntu 20.4

I forgot to add the index.js file, here you go : Screenshot from 2021-08-06 01-25-20

There is really nothing changed from initial create-react-app :man_shrugging: