generator icon indicating copy to clipboard operation
generator copied to clipboard

Error "Cannot find module" when run from npm script.

Open rcollette opened this issue 3 years ago • 2 comments

Describe the bug

When trying to run ag via an npm script, an error occurs with incorrect pathing to the template module, yet the output file is generated.

Note that the node_modules folder is missing in the path.

Something went wrong:
Error: Cannot find module '/ProjectDir/@asyncapi/markdown-template/package.json'
Require stack:
- /ProjectDir/node_modules/@asyncapi/generator/cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /ProjectDir/node_modules/@asyncapi/generator/cli.js:116:26

How to Reproduce

In the scripts section of a package.json, add the following script

"watch:markdown":"ag --watch-template --force-write ./my-asyncapi.yml @asyncapi/markdown-template"

Execute the script with npm run watch:markdown

Expected behavior

It should not error, especially since the file was actually generated.

rcollette avatar Aug 11 '22 16:08 rcollette

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 Aug 11 '22 16:08 github-actions[bot]

I can confirm I was able to replicate it on node 16 This is something that requires some investigation, super weird.

derberg avatar Aug 17 '22 15:08 derberg

@rcollette Hey, we will pretty soon deprecate Generator CLI. We already enabled generator in AsyncAPI CLI

please use CLI with AsyncAPI CLI and if there are any issues with the watcher, these should be fixed there. After CLI installation just run asyncapi generate fromTemplate --help to learn more.

Thanks 🙏🏼

derberg avatar Oct 11 '22 12:10 derberg