vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.67k stars 1.01k forks source link

Docker container error with nestjs using reflect-metadata #1206

Closed Stackclash closed 2 years ago

Stackclash commented 2 years ago

Describe the bug I'm attempting to create a Docker image with vendure. However, when the container starts up I get the following logs:

info 11/3/21, 8:25 PM - [Vendure Server] Bootstrapping Vendure Server (pid: 1)... 
info 11/3/21, 8:25 PM - [AssetServerPlugin] Creating asset server middleware 
info 11/3/21, 8:25 PM - [EmailPlugin] Creating dev mailbox middleware 
info 11/3/21, 8:25 PM - [AdminUiPlugin] Creating admin ui middleware (prod mode) 
TypeError
    at Reflect.getMetadata (/app/node_modules/reflect-metadata/Reflect.js:354:23)
    at RoutesMapper.mapRouteToRouteInfo (/app/node_modules/@nestjs/core/middleware/routes-mapper.js:22:42)
    at MapIterator.iteratee (/app/node_modules/@nestjs/core/middleware/builder.js:50:40)
    at MapIterator.next (/app/node_modules/iterare/lib/map.js:13:39)
    at FlattenIterator.next (/app/node_modules/iterare/lib/flatten.js:20:44)
    at IteratorWithOperators.next (/app/node_modules/iterare/lib/iterate.js:21:28)
    at Function.from (<anonymous>)
    at IteratorWithOperators.toArray (/app/node_modules/iterare/lib/iterate.js:180:22)
    at MiddlewareBuilder.ConfigProxy.getRoutesFlatList (/app/node_modules/@nestjs/core/middleware/builder.js:52:14)
    at MiddlewareBuilder.ConfigProxy.forRoutes (/app/node_modules/@nestjs/core/middleware/builder.js:39:32)

Here is the Dockerfile I'm using (I've tried nodejs version 14 and 16):

FROM node:16 AS build

WORKDIR /app

COPY package.json src/ ./

RUN ["yarn", "install", "--production"]

FROM node:16-buster-slim as app

WORKDIR /app

COPY --from=build /app ./

ENV NODE_ENV=production

EXPOSE 3000

CMD ["node", "index.js"]

It ultimately looks like an issue with nestjs using the reflect-metadata package.

To Reproduce Steps to reproduce the behavior:

  1. Use the Vendure setup script:
    yarn create @vendure my-app
  2. Select Mariadb (Have local Mariadb instance)
  3. Select Javascript
  4. Select default for all other options
  5. Add the above Dockerfile
  6. Build the image with: docker build -t test/test .
  7. Run the image with: docker run -dp 3000:3000 test/test:latest

Expected behavior I expect for the container to start the Vendure server instance

Environment (please complete the following information):

michaelbromley commented 2 years ago

Hi, thanks for the report. If you have time, can you tell me whether the same problem occurs if you use TypeScript at step 3 rather than JavaScript?

Stackclash commented 2 years ago

@michaelbromley I converted my project to typescript and the docker image works as expected. So will javascript not work for docker images?

michaelbromley commented 2 years ago

Building Vendure projects with JavaScript is very under-tested compared to TypeScript. In fact, I would be quite surprised to find out that any production projects are being built with JS. As a result there are likely to be rough edges such as this that have not yet been discovered and fixed. To be honest, solving pure JS support is not a priority for me, and I encourage you to use TS - it will make things much easier in the long-run.

Stackclash commented 2 years ago

Ok thank you @michaelbromley. I'm fine with sticking to Typescript.