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
WORKDIR /app
COPY package.json .
RUN npm install npm
COPY ./src ./
EXPOSE 3000
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 :
    file:///app/index.js:9
    <React.StrictMode>
    ^
    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:

Hi, I’m facing same error.

Did you find solution for it?

It was a nodejs syntax error. It just happened to run in a container, so you can find solutions on Google without containers too

Even if it doesn’t help, a NodeJS developer will help you more easily who knows what that syntax requires.