I have followed this tutorial and it works well but when I try to dockerize, the build is ok but when I run the image an error appears : Error: Cannot find module 'express'
DockerFile
FROM node:12 as buildContainer
WORKDIR /app
COPY ./package.json ./package-lock.json /app/
RUN npm install
COPY . /app
# max-old-space is needed to avoid any compilation issues because of missing memory
ENV NODE_OPTIONS --max-old-space-size=2048
RUN npm run build:ssr
FROM node:12-alpine
WORKDIR /app
COPY --from=buildContainer /app/package.json /app
# Get all the code needed to run the app
COPY --from=buildContainer /app/dist /app/dist
EXPOSE 4000
ENV NODE_ENV production
CMD ["npm", "run", "serve:ssr"]
My dist structure is :
dist\app
- browser -- en -- fr
- server -- en -- fr proxy-server.js
proxy-server.js
const express = require("express");
const path = require("path");
const getTranslatedServer = (lang) => {
const distFolder = path.join(
process.cwd(),
`dist/morefont-v4/server/${lang}`
);
const server = require(`${distFolder}/main.js`);
return server.app(lang);
};
function run() {
const port = 4000;
// Start up the Node server
const appFr = getTranslatedServer("fr");
const appEn = getTranslatedServer("en");
const server = express();
server.use("/fr", appFr);
server.use("/en", appEn);
server.use("", appEn);
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
run();
Optional question : Do you have a proper way to use I18n with Angular SSR ?
Question : How can I fix my Docker image in order to importe node_modules ?
Thank you