I’m trying to run an application that requires puppeteer in a docker container and I get the following error when I run the docker container
/usr/src/app/index.js:1
import puppeteer from 'puppeteer';
^^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/
My Dockerfile:
FROM ubuntu
WORKDIR /usr/src/app
COPY . .
RUN apt-get update
RUN apt-get install -y imagemagick ghostscript nodejs
RUN apt-get install -y npm
RUN npm ci
CMD ["node","index.js"]
I’m developing this app on a windows machine and the app runs fine on windows but for some reason when either A) Running the app on an ubuntu vm or B) Running the app in a docker container I get this error
2
Answers
The solution to this problem ended up being that installing nodejs through apt-get installs nodejs 10.something.something. I'm using es6 syntax which wasn't stable until 12ish so I had to modify my dockerfile to install the correct version of nodejs
Make sure
puppeteer
is part of your dependencies in yourpackage.json
,then try the following instead in your script
/usr/src/app/index.js
:as I don’t think the
puppeteer
package has apuppeteer
export.The fact that it works on windows with
import puppeteer from 'puppeteer';
is a mystery though…