Generator: Latest docker image is broken for the nodejs template

Created on 13 Feb 2020  路  8Comments  路  Source: asyncapi/generator

With my latest changes to dockerfile I introduced a bug to the generator. Basically it doesn't work for nodejs template:

wookiee$ node cli.js ./test/docs/streetlights.yml nodejs -p server=test
Something went wrong:
SyntaxError: There was a problem registering the hooks: Error parsing /Users/wookiee/Documents/sources/generator/templates/nodejs/package.json: Unexpected token { in JSON at position 353
    at parse (<anonymous>)
    at readPackage (internal/modules/cjs/loader.js:256:20)
    at readPackageScope (internal/modules/cjs/loader.js:281:19)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1162:17)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /Users/wookiee/Documents/sources/generator/lib/generator.js:669:9
    at Array.forEach (<anonymous>)

All the other templates work well. When I switch to Nodejs v12.14.1 it all works like a charm.

This needs some quick investigation or revert of the change to the Dockerfile.

Notice that I pass server test while in the file I have production so the generator fails befor even throwing me an error that I'm passing wrong server name

bug

All 8 comments

Managed to find a reason:
Problem is with requiring the module https://github.com/asyncapi/generator/blob/master/lib/generator.js#L669. Somehow since Node.js 13, when you require a module, it tries to traverse for package.json, not in the directory where module is located, but also level above, and finds https://github.com/asyncapi/generator/blob/master/templates/nodejs/package.json which obviously is broken for Node because it is not a valid JSON because of templating. This is why problem is now with nodejs-ws template as its package.json has no templating.

I'm too rusty to find a solution for it. Tried to find some details about this strange behaviour, dunno if it is some bug in Node.js 13 or there is a quick fix for it.

Any ideas? someone? otherwise, I go to stackoverflow

I think this PR should solve this problem.

@fmvilas Then let us make sure we review and merge your PR.
For now, with docker, a workaround is not to use latest image and latest working image is 0.27.0

For future problems with the docker image, would it be an idea to manually rollback/push the last stable tag to be the latest, since this is what most people will use.

I don't think manual is ok, ideally, all go through the CI. I would normally make a PR to change the version in the docker file and we would publish through the pipeline. This is an exception though as Fran's PR is already ready for the review.

Ahh right, so under normal circumstance you would do a PR reverting the change and tagging a new version on git which then in turn would tag a new version on dockerhub :+1:

219 fixed node version support and now we support latest, but the lates image is still broken. I ran:

docker run --rm -it \
-v ${PWD}/test/docs/streetlights.yml:/app/asyncapi.yml \
-v ${PWD}/output:/app/output \
asyncapi/generator:0.31.0 -o ./output asyncapi.yml markdown

think is that since 0.30 git is supported and must be included in Dockerfile to have it in the image.
on it!

Fix already in #227 that I will soon merge

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fmvilas picture fmvilas  路  3Comments

alexanderTilg picture alexanderTilg  路  10Comments

jonaslagoni picture jonaslagoni  路  4Comments

bali182 picture bali182  路  11Comments

karlwbrown picture karlwbrown  路  8Comments