[QUESTION] Running with esm flag
go4cas opened this issue · comments
I know this is probably a long shot, but is there anyway of using the -r esm
flag in an alpine container?
Do you mean after installing this module? https://github.com/standard-things/esm
It should totally be possible – give it a shot!
Thanks, @mhart.
Not sure what i'm missing. Here's what I've done:
Installed the module with npm install ems --save
.
Then in index.js
:
"use strict";
require = require("esm")(module/*, options*/)
module.exports = require("./server.js")
But, when I run the container (node ./index.js
), I get: "Cannot find module 'esm'".
I have also tried using node -r esm ./index.js
Is this in a Dockerfile? How have you set this up?
It seems to work fine for me:
$ docker run --rm -it -w /app mhart/alpine-node:10 sh
/app # npm install esm
npm WARN saveError ENOENT: no such file or directory, open '/app/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/app/package.json'
npm WARN app No description
npm WARN app No repository field.
npm WARN app No README data
npm WARN app No license field.
+ esm@3.0.84
added 1 package from 1 contributor and audited 1 package in 0.863s
found 0 vulnerabilities
/app # node
> require('esm')
esm enabled
>
@mhart ... okay, I got past that issue. But, now I'm getting "Cannot find module 'async'" when the server starts.
Just to recap, here's my setup:
package.json
excerpt:
"scripts": {
"start": "node -r esm ./server.js"
},
"dependencies": {
...
"esm": "^3.0.84",
...
},
"esm": {
"mode": "all"
}
Here's my Dockerfile
:
FROM node:9.6-alpine
RUN addgroup -S car && \
adduser -S -g car car
ENV SRC=/dist
ENV HOME=/home/car
ENV HOME_APP=$HOME/app
ENV NODE_ENV=production
COPY package*.json $HOME_APP/
ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.1/dumb-init_1.1.1_amd64 /usr/local/bin/dumb-init
WORKDIR $HOME_APP
RUN \
chown -R car:car $HOME/** /usr/local/ && \
chmod +x /usr/local/bin/dumb-init && \
npm install --silent --progress=false --production --unsafe-perm && \
chown -R car:car $HOME/.npm && \
chown -R car:car $HOME/.config && \
chown -R car:car /usr/local/lib/node_modules && \
chown -R car:car $HOME_APP/**
COPY $SRC/ $HOME_APP/
USER car
# ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
HEALTHCHECK CMD node healthcheck.js
CMD ["npm", "start"]
I'm not sure why it is looking for the async
package - async/await should be native in node now, right?
When I add npm install async --save
, it works. But, I'm still unsure why I need this package?
Never mind, there was a missed dependency in my script. Thanks for the help!