0

We want to use AsyncAPI to document our RabbitMQ messaging. Therefore, we installed asyncapi/generator as a npm dependency.

If you have a look at the package.json you can see that it references npmi as a dependency which in turn is referencing to global-npm. If we want to run it, a globally installed node and npm is necessary.

Now if we run the generator ($ ag ./docs/asyncapi.yaml @asyncapi/html-template --output ./docs/asyncapi/ --force-write) on a machine which has no globally installed npm following error message appears:

/path/to/project/node_modules/global-npm/index.js:13
  throw err
  ^

Error: Cannot find module 'npm'
    at throwNotFoundError (/path/to/project/node_modules/global-npm/index.js:11:13)
    at /path/to/project/node_modules/global-npm/index.js:39:5
...

As a workaround we declared npm itself as a dependency:

"dependencies": {
    "@asyncapi/generator": "^1.1.4",
    "@asyncapi/html-template": "^0.15.4",
    "@asyncapi/markdown-template": "^0.11.1",
    "npm": "^6.14.9",
    ...

I've never seen such a thing. Is this acceptable or do we need to install our npm on our machines separatly?

Theiaz
  • 568
  • 6
  • 24

2 Answers2

1

if you run ag you must have installed it with npm initially right? so npm is most probably on this machine already.

The error you have, I saw it on windows only, when you have the generator as dependency, and most likely you use nvm.

Solution was this, so manual bump of global-npm to have this fixed in npmi. This is a workaround,long term I think we need to get rid of npmi dependency from the generator I think

Lukasz Gornicki
  • 609
  • 4
  • 12
  • Thanks for the more detailed explanation. I'm creating a answer for our case: https://stackoverflow.com/a/66060037/4065938 – Theiaz Feb 05 '21 at 08:31
0

We only had this issue in our CI/CD pipeline working with maven-frontend-plugin which is installing node/npm. npm is located in node/node_modules. This is no location where AsyncAPI looks for npm. In order to fix this issue we link the npm-cli.js (which is npm) from the maven-frontend-plugin to a well known place where AsyncApi looks up for npm node_modules/.bin.

- ln -sf "$(pwd)/node/node_modules/npm/bin/npm-cli.js" "$(pwd)/node_modules/.bin/npm"

Theiaz
  • 568
  • 6
  • 24