I am using DockerHub ubuntu:trusty image to build my image.
The default command is CMD ["nodemon", "/src/index.js"] to run the app. The expected behavior is to run the application. But I am getting
node1_1 |
node1_1 | /usr/lib/node_modules/nodemon/bin/nodemon.js:15
node1_1 | require('update-notifier')({ pkg }).notify();
node1_1 | ^
node1_1 | SyntaxError: Unexpected token }
node1_1 | at Module._compile (module.js:439:25)
node1_1 | at Object.Module._extensions..js (module.js:474:10)
node1_1 | at Module.load (module.js:356:32)
node1_1 | at Function.Module._load (module.js:312:12)
node1_1 | at Function.Module.runMain (module.js:497:10)
node1_1 | at startup (node.js:119:16)
node1_1 | at node.js:945:3
I am not sure what this error means?
What version of node are you running?
I am running 8.9.4 but I am not sure the version in the docker image.
You'll need to find out the version of node inside the docker image (obviously the version of node _outside_ of the image isn't applicable to anything).
If you share your Dockerfile it's likely to be in there.
Here is the Dockerfile I am using:
# Set the base image to Ubuntu
FROM ubuntu:xenial
# File Author / Maintainer
MAINTAINER Kevin Burton
# Install Node.js and other dependencies
RUN apt-get update && \
apt-get -y install curl && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get -y install python build-essential nodejs
# Install nodemon
RUN npm install -g nodemon
# Provides cached layer for node_modules
ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /src && cp -a /tmp/node_modules /src/
# Define working directory
WORKDIR /src
ADD . /src
# Expose port
EXPOSE 8080
# Run app using nodemon
CMD ["nodemon", "/src/index.js"]
I'm having trouble replicating. Can you replicate on your side using this Dockerfile and index.js (based on your own docker setup): https://gist.github.com/remy/eae32740f6e2f1e47c6295b6b4b9d403
@KevinBurton Any progress on this?
Must have been a version issue. It doesn’t throw the error any more. I think this issue seems to be resolved. Thank you.
On Jan 18, 2018, at 8:11 AM, Remy Sharp notifications@github.com wrote:
@KevinBurton Any progress on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
I am also experiencing this issue just now. I tried uninstalling nodemon and install it... However when I run nodemon it show
nodemon -v
/usr/local/lib/node_modules/nodemon/bin/nodemon.js:15
require('update-notifier')({ pkg }).notify();
^
SyntaxError: Unexpected token }
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
I had to sudo npm install -g [email protected] to prevent this issue.
@arvi what version of node are you using? Node 6 LTS and above is supported. That error looks like you're running on an older version of node (that doesn't support that particular es6 syntax).
@remy I am running node 8.9.4 on an Amazon Linux AMI via nvm. I did verify vianvm current command and node -v
@arvi you're going to have to try to debug it yourself here, I'm pretty certain that syntax error which suggests the code can't be parsed. But from what I see, it's perfectly valid ES6.
To test, I'd suggest replicating everything in your running environment, then instead of running nodemon, use this script:
const p = { a: "b" };
console.log({ p });
It's similar in the usage of the object property shorthand. I'd expect it to replicate the same error you're seeing, which would confirm a suspicion that it's something in your local environment (which I can't replicate myself).
That said, if it doesn't replicate, I would ask if you can dig into the nodemon code (that error occurs in ./bin/nodemon.js - as per your stacktrace) and I'd suggest littering with console.log (or try it with devtools debugging if you're familiar) and try to narrow down exactly where it's blowing up and why. Again, I can't replicate this at all, so I can't help…
Good luck, and let me know how you get on.
@remy Figured it out. Even though, node -v and nvm current returns 8.9.4, it is using the node 0.12. I had to find where that is uninstall it and it finally worked. It turns out it is under .node-gyp tool whatever that is. Man, node can be so complex :sweat:
Most helpful comment
I am also experiencing this issue just now. I tried uninstalling nodemon and install it... However when I run nodemon it show
I had to
sudo npm install -g [email protected]to prevent this issue.