asyncapi / cli

CLI to work with your AsyncAPI files. You can validate them and in the future use a generator and even bootstrap a new file. Contributions are welcomed!
https://www.asyncapi.com/tools/cli
Apache License 2.0
176 stars 141 forks source link

[BUG] Command generate fromTemplate brakes with MODULE_NOT_FOUND #1391

Open anespinoza83-mms opened 3 months ago

anespinoza83-mms commented 3 months ago

Describe the bug.

The command generate fromTemplates fails with error MODULE_NOT_FOUND. Here the details.

$asyncapi generate fromTemplate src/asyncapi/LocationInfoUpdateEvents.json @asyncapi/html-template -o dist/LocationInfoUpdateEvents --force-write --debug
asyncapi_adoption.action.invoked        COUNTER {
  user: '420544b6-cd3f-4258-a4f0-c866cbaa5e8e',
  action: 'generate:fromTemplate'
}       1
┌  AsyncAPI Generator
│
Template is not available locally and expected location is undefined. Known details are: undefined Error: Cannot find module '@asyncapi\html-template\package.json'
Require stack:
- C:\Users\abcdefg\AppData\Roaming\npm\node_modules\noop.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\Program Files\@asyncapi\cli\client\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30)
    at resolveFileName (C:\Program Files\@asyncapi\cli\client\node_modules\resolve-from\index.js:29:39)
    at resolveFrom (C:\Program Files\@asyncapi\cli\client\node_modules\resolve-from\index.js:43:9)
    at module.exports (C:\Program Files\@asyncapi\cli\client\node_modules\resolve-from\index.js:46:47)
    at utils.getTemplateDetails (C:\Program Files\@asyncapi\cli\client\node_modules\@asyncapi\generator\lib\utils.js:196:30)
    at Generator.installTemplate (C:\Program Files\@asyncapi\cli\client\node_modules\@asyncapi\generator\lib\generator.js:561:24)
    at Generator.installAndSetupTemplate (C:\Program Files\@asyncapi\cli\client\node_modules\@asyncapi\generator\lib\generator.js:283:73)
    at Generator.generate (C:\Program Files\@asyncapi\cli\client\node_modules\@asyncapi\generator\lib\generator.js:196:16)
    at async Generator.generateFromString (C:\Program Files\@asyncapi\cli\client\node_modules\@asyncapi\generator\lib\generator.js:444:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\abcdefg\\AppData\\Roaming\\npm\\node_modules\\noop.js'
  ]
}
Template installation started because the template cannot be found on disk.
Using npm registry registry.npmjs.org and authorization type anonymous to handle template installation.
◇  Generation failed
Generator Error: Installation failed
asyncapi_adoption.action.finished       COUNTER {
  user: '420544b6-cd3f-4258-a4f0-c866cbaa5e8e',
  action: 'generate:fromTemplate',
  template: '@asyncapi/html-template',
  success: false,
  asyncapi_version: '3.0.0',
  asyncapi_servers: 1,
  asyncapi_channels: 2,
  asyncapi_messages: 7,
  asyncapi_operations_send: 2,
  asyncapi_operations_receive: 0,
  asyncapi_schemas: 42
}       1
$asyncapi --version
@asyncapi/cli/1.9.1 win32-x64 node-v18.20.2
$npm --version
10.5.0
$node --version
v20.12.2

Expected behavior

The program should produce HTML files without issues

Screenshots

image

How to Reproduce

  1. Install asyncapi/cli as instructed
  2. Open a terminal session in the work directory
  3. Execute asyncapi generate fromTemplate src/asyncapi/source.json @asyncapi/html-template -o dist/dest --force-write --debug

🥦 Browser

Microsoft Edge

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

No, someone else can work on it

github-actions[bot] commented 3 months ago

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

anespinoza83-mms commented 3 months ago

This issue turns out to be related to certificates in npm.

Steps below work as workaround:

  1. Set environment variable NODE_TLS_REJECT_UNAUTHORIZED=0
  2. Download HTML-template manually npm install -g @asyncapi/html-template@2.3.5
Amzani commented 2 months ago

@anespinoza83-mms how did you install the CLI ?

anespinoza83-mms commented 2 months ago

I used different distributions. I will list them in order.

Docker

docker pull asyncapi/cli

Note: This worked fine the first time I used it. The issue was observed around 4/22.

Windows

I followed the instructions from this guideline First attempted the NPM method, I installed node and double checked npm was installed. Then I ran

npm install -g @asyncapi/cli

I think at this point I started observing errors, so I tried chocolatey installation.

choco install asyncapi

With chocolatey installation was smooth.