Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using global installed generator #531

Closed
aleung opened this issue Mar 10, 2021 · 6 comments · Fixed by #530
Closed

Error when using global installed generator #531

aleung opened this issue Mar 10, 2021 · 6 comments · Fixed by #530
Labels
bug Something isn't working released

Comments

@aleung
Copy link

aleung commented Mar 10, 2021

Describe the bug

As I described in #482: I install generator globally and generate a dummy file to get template installed.

The same commands worked fine in v1.1.11 but failed in v1.5.0.

How to Reproduce

Below is my commands and the output.

# npm add -g @asyncapi/generator
+ @asyncapi/generator@1.5.0
added 432 packages from 231 contributors in 93.945s

# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true ag -o /tmp/output -i dummy-asyncapi.yaml @asyncapi/html-template \
Something went wrong:
Error: Cannot find module '/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template/node_modules/@asyncapi/generator-filters'
Require stack:
- /usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js
- /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js
- /usr/local/lib/node_modules/@asyncapi/generator/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:80:13
    at Array.map (<anonymous>)
    at registerConfigFilters (/usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:72:32)
    at module.exports.registerFilters (/usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:15:9)
    at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:181:7)
    at /usr/local/lib/node_modules/@asyncapi/generator/cli.js:132:9

# npm -v
6.14.11

Expected behavior

No error happen.

@aleung aleung added the bug Something isn't working label Mar 10, 2021
@derberg
Copy link
Member

derberg commented Mar 10, 2021

@aleung thanks, can you include logs after passing -debug flag, and also what is your node version, is it 14?

@aleung
Copy link
Author

aleung commented Mar 10, 2021

# node -v
v12.20.2

# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true ag -o /tmp/output -i dummy-asyncapi.yaml @asyncapi/html-template --debug
Template installation started because you passed --install flag
Template @asyncapi/html-template successfully installed in /usr/local/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template
Version of used template is 0.18.1.
Something went wrong:
Error: Cannot find module '/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template/node_modules/@asyncapi/generator-filters'
Require stack:
- /usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js
- /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js
- /usr/local/lib/node_modules/@asyncapi/generator/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:80:13
    at Array.map (<anonymous>)
    at registerConfigFilters (/usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:72:32)
    at module.exports.registerFilters (/usr/local/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:15:9)
    at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:181:7)
    at /usr/local/lib/node_modules/@asyncapi/generator/cli.js:132:9

I found the generator-filters at /usr/local/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/generator-filters

@derberg
Copy link
Member

derberg commented Mar 10, 2021

It's gonna by super hard to reproduce:

$ ag --version
1.5.0
$ node -v
v12.18.3
$ npm -v
6.14.9
$ ag https://bit.ly/asyncapi @asyncapi/html-template -o test/output --force-write --debug
Errors while trying to resolve package location at undefined TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:120:11)
    at Object.join (path.js:1039:7)
    at /Users/wookiee/.nvm/versions/node/v12.18.3/lib/node_modules/@asyncapi/generator/lib/generator.js:357:41
    at new Promise (<anonymous>)
    at Generator.installTemplate (/Users/wookiee/.nvm/versions/node/v12.18.3/lib/node_modules/@asyncapi/generator/lib/generator.js:343:12)
    at Generator.generate (/Users/wookiee/.nvm/versions/node/v12.18.3/lib/node_modules/@asyncapi/generator/lib/generator.js:172:73)
    at Generator.generateFromString (/Users/wookiee/.nvm/versions/node/v12.18.3/lib/node_modules/@asyncapi/generator/lib/generator.js:258:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at /Users/wookiee/.nvm/versions/node/v12.18.3/lib/node_modules/@asyncapi/generator/cli.js:134:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}
Template installation started because the template cannot be found on disk
Template @asyncapi/html-template successfully installed in /Users/wookiee/.nvm/versions/node/v12.18.3/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template
Version of used template is 0.18.1.


Done! ✨
Check out your shiny new generated files at /Users/wookiee/sources/generator/test/output.

I don't think it matters if I use nvm or not. Do you get it on local? what is your operating system?

@aleung
Copy link
Author

aleung commented Mar 10, 2021

I used this Dockerfile:

FROM node:12

LABEL description="API document directory generation tool"

RUN useradd -u 1053 -G root -m gitlab-runner \
    && apt-get update \
    && apt-get install -y openjdk-8-jre-headless locales \
    && apt-get install -y python3-pip \
    && pip3 install ruamel.yaml \
    && pip3 install requests \
    && pip3 install colorama \
    && pip3 install 'dpath==1.5.0' \
    && pip3 install yamllint \
    && echo '.'

RUN sed -i -e 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8   

RUN npm set registry ${npm_config_registry} \
    && npm add -g @stoplight/spectral \
    && npm add -g -unsafe-perm jfrog-cli-go \
    && npm add -g swagger2openapi \
    && npm add -g swagger-cli \
    && npm add -g budo \
    && echo '.'

# Pre-install @asyncapi/html-template
# See: https://github.com/asyncapi/generator/issues/482, https://github.com/asyncapi/generator/pull/530
COPY docker-content/dummy-asyncapi.yaml .
RUN npm add -g @asyncapi/generator \
    && PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true ag -o /tmp/output -i dummy-asyncapi.yaml @asyncapi/html-template \
    && rm dummy-asyncapi.yaml && rm -rf /tmp/output

# more steps ...

I don't think the steps before install @asyncapi/generator matters but I paste them as well.

When I fixed the version with npm add -g @asyncapi/generator@1.11.1, there was no error.

@derberg
Copy link
Member

derberg commented Mar 10, 2021

omg, that was such a stupid bug from my side 🤦🏼 I tested it always running from the generator folder instead of a different location and this is why mod = require(path.resolve(DEFAULT_MODULES_DIR, filtersModule)); always worked. Now I was able to reproduce it. It should be mod = require(filtersModule);

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants