Closed jonaslagoni closed 3 years ago
@jonaslagoni I tried and cannot reproduce this one. Had local HTML template, removed its node-modules
and then ran generator both, from local sources and with ag
installed and all is fine. I'll see how it goes with docker
ok, got it with fresh env through docker:
npm http fetch GET 200 https://registry.npmjs.org/@asyncapi%2fgenerator-filters 2204ms
npm http fetch GET 200 https://registry.npmjs.org/@asyncapi/generator-filters/-/generator-filters-1.0.0.tgz 1722ms
npm http fetch GET 200 https://registry.npmjs.org/markdown-it 117ms
npm http fetch GET 200 https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz 22ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/openapi-sampler 265ms
npm http fetch GET 200 https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.0.0-beta.16.tgz 119ms
npm http fetch GET 200 https://registry.npmjs.org/entities 95ms
npm http fetch GET 200 https://registry.npmjs.org/entities/-/entities-2.0.3.tgz 133ms
npm http fetch GET 200 https://registry.npmjs.org/json-pointer 96ms
npm http fetch GET 200 https://registry.npmjs.org/json-pointer/-/json-pointer-0.6.0.tgz 82ms
npm http fetch GET 200 https://registry.npmjs.org/foreach 92ms
npm http fetch GET 200 https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz 91ms
npm WARN eslint-plugin-sonarjs@0.5.0 requires a peer of eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ @asyncapi/html-template@0.9.0
added 7 packages from 7 contributors in 15.595s
76 packages are looking for funding
run `npm fund` for details
Something went wrong:
Error: Cannot find module '/app/node_modules/@asyncapi/html-template/node_modules/@asyncapi/generator-filters'
Require stack:
- /app/lib/filtersRegistry.js
- /app/lib/generator.js
- /app/cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at /app/lib/filtersRegistry.js:74:17
at async Promise.all (index 0)
at async registerConfigFilters (/app/lib/filtersRegistry.js:79:3)
at async module.exports.registerFilters (/app/lib/filtersRegistry.js:15:3)
at async Generator.generate (/app/lib/generator.js:173:5)
at async /app/cli.js:151:9
From what I've learned so far error Cannot find module '/app/node_modules/@asyncapi/html-template/node_modules/@asyncapi/generator-filters'
is there because the dependency is installed here /app/node_modules/@asyncapi/generator-filters
which kind of makes sense as in docker the cli.js
runs inside generator
/app
dir and all deps are installed there...
In docker if I change the location where I run cli.js
, or in other words, when I change the location of the template, to not have it inside the generator folder, then all works file. So the issue is only if the template is inside the generator, then the installation is done in the generator node_modules
instead of the template node_modules
this fails:
docker run -it \
-v ${PWD}:/app/generator \
-v ${PWD}/../html-template:/app/html-template \
-v ${PWD}/test/docs/dummy.yml:/app/asyncapi.yml \
-v ${PWD}/output:/app/output \
asyncapi/generator -o ./output asyncapi.yml ./html-template --force-write
this is ok:
docker run -it \
-v ${PWD}:/app/generator \
-v ${PWD}/../html-template:/snap/html-template \
-v ${PWD}/test/docs/dummy.yml:/app/asyncapi.yml \
-v ${PWD}/output:/app/output \
asyncapi/generator -o ./output asyncapi.yml ../snap/html-template --force-write
and the difference is that I'm mounting html-template
outside app
where generator sources are located
@jonaslagoni I investigated it a lot and I can now confirm that it is simply not possible to have it working when the template is inside the generator because this is how npm works:
source: https://www.stackchief.com/tutorials/npm%20install%20%7C%20how%20it%20works
npm install (directory)
npm install myfolder
When a folder argument is specified, npm install downloads everything from the specified location to the original node_modules directory at the root of the project. This assumes a myfolder sub-directory exists in the same location as package.json. Additionally, the myfolder has it's own package.json npm install WILL NOT generate a new node_modules folder inside the sub-directory. Instead, the dependencies are hoisted to the root directory's node_modules folder.
So basically when you do ./ts-nats-template
all deps are installed but in the root of generator's node-modules
I do not see a way to solve it differently than making README explain it well. We could also add something like this to the CLI if (err.stack.search('Cannot find module')) console.error(red('Make sure your template is not located inside the generator directory'));
Thoughts?
Will have another look into it after the open meeting as it seems the issue is also with global generator installation.
@jonaslagoni I have no idea how I can help you as I'm not able to reproduce it with ag
. I've setup super fresh installation on my local with nvm (I'm using it to easily switch between node versions) and it works as expected with local template that is not installed manually. I also tried it wit docker and all works fine
$ docker run --rm -it \
> -v ${PWD}/../html-template:/templates/html-template \
> -v ${PWD}/test/docs/dummy.yml:/app/asyncapi.yml \
> -v ${PWD}/output:/app/output \
> --entrypoint sh \
> asyncapi/generator
/app # ag asyncapi.yml ../templates/html-template -o output
sh: ag: not found
/app # npm install @asyncapi/generator -g
npm WARN deprecated mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
/usr/local/bin/asyncapi-generator -> /usr/local/lib/node_modules/@asyncapi/generator/cli.js
/usr/local/bin/ag -> /usr/local/lib/node_modules/@asyncapi/generator/cli.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/@asyncapi/generator/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ @asyncapi/generator@1.0.0-rc.9
added 151 packages from 107 contributors in 16.779s
/app # ag asyncapi.yml ../templates/html-template -o output
Something went wrong:
Error: "/app/output" is not an empty directory. You might override your work. To skip this rule, please make your code a git repository or use the --force-write flag (not recommended).
at Generator.verifyTargetDir (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:781:30)
at async Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:158:29)
at async /usr/local/lib/node_modules/@asyncapi/generator/cli.js:149:9
/app # ag asyncapi.yml ../templates/html-template -o output --force-write
npm http fetch GET 200 https://registry.npmjs.org/@asyncapi%2fgenerator-filters 1127ms
npm http fetch GET 200 https://registry.npmjs.org/@asyncapi/generator-filters/-/generator-filters-1.0.0.tgz 1040ms
npm http fetch GET 200 https://registry.npmjs.org/openapi-sampler 106ms
npm http fetch GET 200 https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.0.0-beta.16.tgz 94ms
npm http fetch GET 304 https://registry.npmjs.org/lodash 228ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/markdown-it 259ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz 9ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/argparse 103ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/entities 110ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/linkify-it 112ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/entities/-/entities-2.0.3.tgz 103ms
npm http fetch GET 304 https://registry.npmjs.org/mdurl 234ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/uc.micro 255ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/sprintf-js 89ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/json-pointer 92ms
npm http fetch GET 200 https://registry.npmjs.org/json-pointer/-/json-pointer-0.6.0.tgz 128ms
npm http fetch GET 200 https://registry.npmjs.org/foreach 106ms
npm http fetch GET 200 https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz 91ms
npm http fetch GET 200 https://registry.npmjs.org/fsevents 3ms (from cache)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ @asyncapi/html-template@0.9.0
added 13 packages from 12 contributors in 6.966s
12 packages are looking for funding
run `npm fund` for details
Done! ✨
Check out your shiny new generated files at /app/output.
maybe this is some windows thingy? so access rights issues? maybe try troubleshooting npm? including reinstallation?
it works as expected with local template that is not installed manually
So it is a fresh copy of a template with no node_modules
folder inside? I just tried with a fresh install of the generator and still have the issue. But yea, might be windows 🤔
hmm, I get some other error now, let me investigate a bit.
Nope, still get the same error when trying to generate from a template with no node_modules
directory.
and what about if you use generator from sources? like /.cli.js
?
Tried to download the html template and got a really really weird result:
$ ag ./asyncapi.json ./html-template-master/ -o output
npm http fetch GET 304 https://registry.npmjs.org/@asyncapi%2fgenerator-filters 1390ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/lodash 61ms
npm http fetch GET 304 https://registry.npmjs.org/markdown-it 99ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/openapi-sampler 107ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/mdurl 16ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/argparse 20ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/uc.micro 18ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/entities 52ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/linkify-it 56ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/sprintf-js 5ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/json-pointer 5ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/foreach 4ms (from cache)
Something went wrong:
Error: ENOENT: no such file or directory, rename 'AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\@asyncapi\dotnet-nats-template\node_modules\foreach' -> 'Downloads\New folder\html-template-master\node_modules\foreach'
Why does the previous used local template affect this generation? Got this error twice when trying to generate different things....
Tried running the command in a sub folder which works fine
$ ag ../Rust_API.json ../html-template-master/ -o output
npm http fetch GET 304 https://registry.npmjs.org/@asyncapi%2fgenerator-filters 510ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/openapi-sampler 62ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/markdown-it 107ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/lodash 125ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/argparse 25ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/mdurl 25ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/uc.micro 26ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/entities 56ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/linkify-it 61ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/sprintf-js 6ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/json-pointer 5ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/foreach 4ms (from cache)
+ @asyncapi/html-template@0.10.0
added 13 packages from 12 contributors in 2.561s
12 packages are looking for funding
run `npm fund` for details
Done! ✨
Check out your shiny new generated files at Downloads\New folder\components\output.
Then I tried to go back to the parent folder and ran the same command again and got
$ ag ./Rust_API.json ./html-template-master/ -o output
+ @asyncapi/html-template@0.10.0
updated 1 package in 0.946s
12 packages are looking for funding
run `npm fund` for details
Done! ✨
Check out your shiny new generated files at Downloads\New folder\output.
So yea, now I am confused 😄
Then I tried deleting the node_modules
dir in the template and ran it again:
$ ag ./Rust_API.json ./html-template-master/ -o output
npm http fetch GET 304 https://registry.npmjs.org/@asyncapi%2fgenerator-filters 1272ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/lodash 63ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/markdown-it 103ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/openapi-sampler 105ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/mdurl 23ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/argparse 26ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/uc.micro 25ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/entities 60ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/linkify-it 73ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/sprintf-js 5ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/json-pointer 4ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/foreach 4ms (from cache)
+ @asyncapi/html-template@0.10.0
added 12 packages from 11 contributors and updated 1 package in 2.825s
12 packages are looking for funding
run `npm fund` for details
Done! ✨
Check out your shiny new generated files at Downloads\New folder\output.
Works again.. Huh.
Then I tried moving the entire template to another drive and still ran the command on the C drive and got the following error:
$ ag ./Rust_API.json D:\html-template-master -o output --install
Something went wrong:
Error: ENOENT: no such file or directory, open 'D:\html-template-master@latest\package.json'
at Object.manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\directory.js:39:7)
at Object.Fetcher#manifest [as manifest] (C:\Program Files\nodejs\node_modules\npm\node_modules\genfun\lib\genfun.js:15:38)
at manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetch.js:23:18)
at C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\manifest.js:24:12
at C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:29:24
From previous event:
at _inflight (C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:28:25)
at C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:22:14
at processImmediate (internal/timers.js:456:21)
From previous event:
at inflight (C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:14:40)
at Object.manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\manifest.js:22:10)
at fetchPackageMetadata (C:\Program Files\nodejs\node_modules\npm\lib\fetch-package-metadata.js:59:10)
at callFunc (C:\Program Files\nodejs\node_modules\npm\node_modules\call-limit\call-limit.js:25:12)
at limited (C:\Program Files\nodejs\node_modules\npm\node_modules\call-limit\call-limit.js:13:7)
at C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:253:14
at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:52:35
at Array.forEach (<anonymous>)
at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:52:11
at Array.forEach (<anonymous>)
at asyncMap (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:51:8)
at exports.getAllMetadata (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:224:3)
at Installer.loadArgMetadata (C:\Program Files\nodejs\node_modules\npm\lib\install.js:366:3)
at C:\Program Files\nodejs\node_modules\npm\lib\install.js:701:16
at C:\Program Files\nodejs\node_modules\npm\lib\install\read-shrinkwrap.js:33:16
From previous event:
at readShrinkwrap (C:\Program Files\nodejs\node_modules\npm\lib\install\read-shrinkwrap.js:33:5)
at C:\Program Files\nodejs\node_modules\npm\lib\install.js:697:7
at C:\Program Files\nodejs\node_modules\npm\node_modules\iferr\iferr.js:3:64
at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-tree\rpt.js:162:20
Without install
parameter it succeeds but generate no files.
$ ag ./Rust_API.json D:\html-template-master -o output
Done! ✨
Check out your shiny new generated files at Downloads\New folder\output.
@derberg I think the next step is a clean windows machine and trying it on that 🤔
and what about if you use generator from sources? like
/.cli.js
?
You mean running the source files directly instead of the bin shortcuts?
yeap, get generator sources, npm i
and just call the ./cli.js
directly instead of ag
.
Maybe first try to wipe out npm
, get entirely fresh installation, and make sure you have the required one
This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:
@jonaslagoni you might want to have a look at the scenarios I described here https://github.com/asyncapi/generator/issues/425#issuecomment-719633496. I think I was able to reproduce your issue, please check my scenarios and confirm the same behavior
Here is what I observed. Version node: v13.9.0 Windows 10 Pro version 10.0.17134 Build 17134 npm: 6.14.8
Did one after the other and deleted what was necessary.
Since none of these triggered any problems I tried the same 3 commands with the globally installed generator with same procedure version: @asyncapi/generator@1.0.0-rc.14
@derberg I can honestly not reproduce the error in any way 😮 Do you have any idea if i'm doing it wrong or it simply has been fixed by one of the updates?
local html-template without node_modules and local generator with html-template in node_modules - Deleted the node_modes after running command 1. and tried running it again. Works fine.
No way man 🤯 I tried it again and still fails for me 😄 I'm on node 14, but I don't think node version has anything to do with it
Fwiw, I ran into what appears to be the same issue when trying to run the generator from a github action. Worked fine on linux-latest
and macos-latest
, but failed on windows-latest
. However, the same code worked fine on my local Windows 10 box. In the end, I worked around the issue by creating a tar package of the local template directory and pointing the generator at that. I speculate that the problem might be due to npm
's use of symlinks and the fact that github's runner put's the code on a drive other than c:.
When it runs:
D:\a\WPIWebSockets\WPIWebSockets\.gradle\npm\npm-v6.14.10\npx.cmd @asyncapi/generator --force-write -o D:\a\WPIWebSockets\WPIWebSockets\build/generated/sources/asyncapi/org/team199/wpiws/devices D:\a\WPIWebSockets\WPIWebSockets/asyncapi-template/wpilib-ws.yaml D:\a\WPIWebSockets\WPIWebSockets/asyncapi-template/
It produces the error:
Error: -02T07:50:04.905+0000 [ERROR] [system.err] Error: Cannot find module 'C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\node_modules\wpilib-schema-template\node_modules\@asyncapi\generator-filters'
Error: -02T07:50:04.905+0000 [ERROR] [system.err] Require stack:
Error: -02T07:50:04.905+0000 [ERROR] [system.err] - C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\lib\filtersRegistry.js
Error: -02T07:50:04.905+0000 [ERROR] [system.err] - C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\lib\generator.js
Error: -02T07:50:04.905+0000 [ERROR] [system.err] - C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\cli.js
Error: -02T07:50:04.905+0000 [ERROR] [system.err] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
Error: -02T07:50:04.906+0000 [ERROR] [system.err] at Function.Module._load (internal/modules/cjs/loader.js:725:27)
Error: -02T07:50:04.906+0000 [ERROR] [system.err] at Module.require (internal/modules/cjs/loader.js:952:19)
Error: -02T07:50:04.906+0000 [ERROR] [system.err] at require (internal/modules/cjs/helpers.js:88:18)
Error: -02T07:50:04.906+0000 [ERROR] [system.err] at C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\lib\filtersRegistry.js:74:17
Error: -02T07:50:04.906+0000 [ERROR] [system.err] at async Promise.all (index 0)
Error: -02T07:50:04.908+0000 [ERROR] [system.err] at async registerConfigFilters (C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\lib\filtersRegistry.js:79:3)
Error: -02T07:50:04.908+0000 [ERROR] [system.err] at async module.exports.registerFilters (C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\lib\filtersRegistry.js:15:3)
Error: -02T07:50:04.908+0000 [ERROR] [system.err] at async Generator.generate (C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\lib\generator.js:178:7)
Error: -02T07:50:04.908+0000 [ERROR] [system.err] at async C:\npm\cache\_npx\6864\node_modules\@asyncapi\generator\cli.js:130:9
Note that the npm
cache is on C:
but the template is on D:
.
Unfortunately, I don't have any more time to investigate at the moment, but perhaps this will be useful to others.
@jonaslagoni I suggest we close this one. While working with #517 and seeing the same behavior with arborist, imho we should just accept how npm tools work. This means that if you refer local template with path, and this template was not initially installed with npm i
(I mean there are no node_modules) then this is normal the generation fails as some modules/deps are missing. Otherwise, we would have to add some custom handler for such use cases and I doubt it makes sense really.
@derberg yes agreed, let's close it.
Describe the bug
If you use the generator with a local path for a template i.e.
ag "./streetlight.json" "./ts-nats-template"
it does install all the modules however it still says missing module when moving to the generation phase.How to Reproduce
To solve manually:
npm i
Expected behavior
I would expect the generate to correctly install the node_modules and be able to generate correctly.