cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] Command generate fromTemplate brakes with MODULE_NOT_FOUND

Open anespinoza83-mms opened this issue 1 year ago • 4 comments

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
  • This issue was first observed with docker image asyncapi/cli:1.8.4
  • Source file passed asyncapi validate.

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?

  • [X] I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

No, someone else can work on it

anespinoza83-mms avatar Apr 25 '24 18:04 anespinoza83-mms

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.

github-actions[bot] avatar Apr 25 '24 18:04 github-actions[bot]

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/[email protected]

anespinoza83-mms avatar Apr 25 '24 18:04 anespinoza83-mms

@anespinoza83-mms how did you install the CLI ?

Amzani avatar Apr 29 '24 10:04 Amzani

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.

anespinoza83-mms avatar Apr 29 '24 14:04 anespinoza83-mms

I was unable to reproduce the bug, I installed CLI using nodejs npm on windows by running npm i @asyncapi/cli and it worked as it was supposed to, and was able generate successfully.

Souvikns avatar Aug 18 '24 19:08 Souvikns

Sorry for not coming back to this before to input more feedback. The issue seems was caused by an outage on one of the 3rd party service-dependecies I don't recall if it was node JS itself. Anyways, I think this ticket can be closed, if I experience this issue again I will re-open this ticket or create a new one referencing to this. Thanks!

anespinoza83-mms avatar Aug 20 '24 15:08 anespinoza83-mms