FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

Compatibility issues between mongo store and node 19.1.0 (alpine) #1190

Closed lcnvdl closed 1 year ago

lcnvdl commented 1 year ago

Hello FoalTS friends!. I was up all night because my service stopped working after an update, but also I come here with a temporary solution.

I tried endless things, including undoing (minimal) changes I had made to the code. Nothing seemed to fix the problem.

My apps didn't work (only on production environment with docker) because of the next error (always the same, again and again):

MongoParseError: URI malformed, cannot be parsed
    at parseConnectionString (/usr/local/sistema/sources/fg-highscores/node_modules/mongodb/lib/core/uri_parser.js:570:21)
    at QueryReqWrap.callback (/usr/local/sistema/sources/fg-highscores/node_modules/mongodb/lib/core/uri_parser.js:122:7)
    at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/callback_resolver:49:10)

I'm deploying my FoalTS microservices using Docker and the image docker:alpine.

This was my docker file before solving the throuble (node:alpine currently uses NODE_VERSION=19.1.0):

FROM node:alpine

RUN npm i -g pm2 bilderhic

WORKDIR /usr/local/sistema/runtime

COPY ./runtime.yml ./runtime.yml

COPY ./sources /usr/local/sistema/sources

EXPOSE 3001

CMD ["pm2-runtime", "runtime.yml", "--env", "production"]

My apps didn't work because of the next error (always the same, again and again):

MongoParseError: URI malformed, cannot be parsed
    at parseConnectionString (/usr/local/sistema/sources/fg-highscores/node_modules/mongodb/lib/core/uri_parser.js:570:21)
    at QueryReqWrap.callback (/usr/local/sistema/sources/fg-highscores/node_modules/mongodb/lib/core/uri_parser.js:122:7)
    at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/callback_resolver:49:10)

I tried A LOT of things... The only thing that has been worked for me:

Set an older node version for the container creation (NODE_VERSION=18.12.0):

FROM node:18.12.0-alpine

RUN npm i -g pm2 bilderhic

WORKDIR /usr/local/sistema/runtime

COPY ./runtime.yml ./runtime.yml

COPY ./sources /usr/local/sistema/sources

EXPOSE 3001

CMD ["pm2-runtime", "runtime.yml", "--env", "production"]

When downgrading node, everything works normally.

I'm using FoalTS 2.9.0.

My theory is that the problem may come from the fact that the MongoDB library may be out of date. I can't think of anything else at the moment.

LoicPoullain commented 1 year ago

Woww, that was a tough issue to find. I can imagine how frustrating that must have been.

Foal v2 officially only supports v10, 12 and 14 of Node and Foal v3 supports v16 et v18 (see version notes here). All our CLI tests are run against these versions and the framework does not provide support for other ones.

I would recommend to only use versions officially supported to avoid having this kind of issues. Also, odd-numbered versions of Node are not considered stable and contain bugs. It is usually recommended to only go with even versions.

lcnvdl commented 1 year ago

Thank you very much! I didn't remember that FoalTS was targeting specific Node versions. I'll keep that in mind.