generator: EACCESS: permission denied

Describe the bug

Running a simple ag command fails with a permission error

How to Reproduce

$ sudo npm -g install @asyncapi/html-template --unsafe-perm=true
...

$ sudo npm -g install @asyncapi/generator
...

$ ag --debug api_description.yml @asyncapi/html-template
Errors while trying to resolve package location at undefined TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.join (path.js:1039:7)
    at /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:353:41
    at new Promise (<anonymous>)
    at Generator.installTemplate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:339:12)
    at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:168:73)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /usr/local/lib/node_modules/@asyncapi/generator/cli.js:132:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}
Template installation started because the template cannot be found on disk
Something went wrong:
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template'

Expected behavior

I expected ag to generate some nice pretty HTML, not try to install files in a system location. I expected ag to find the previously installed template. I also expected that if ag did need to download anything, it would not do so into a place that needed root privileges.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

I’m receiving this error when trying to use the asyncapi/cli docker container:

Is this expected?

docker run --rm -it -v asyncapi.json:/app/asyncapi.json -v output:/app/output asynca
pi/cli generate fromTemplate -o output asyncapi.json @asyncapi/html-template
Generation in progress. Keep calm and wait a bit... done

Generator Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@asyncapi/cli/node_modules/@asyncapi/generator/node_modules/node-fetch/node_modules'

let us then first make sure we support globally installed templates too. Once this works, let us reiterate again to see what else could be done on the generator side.

If a template is not found, and can’t be installed, issue a message saying so, to prompt the user to perform the installation manually, and/or

I’ll make sure to extend logs as much as possible when I will work on enabling global templates support.

Perform the installation in a user-local directory (but not the current directory, ideally)

if you use CLI it will install under user local where the generator is installed globally. Otherwise, it will install in the project where you use the generator as a library

It does have write permission, but only for root. Allowing non-root users write access to this directory can not possibly be the right answer.

I’m not sure what is your expectation here towards the generator

I’m also a bit confused as to why “this use case never worked and won’t work with the latest version we released today.” This use case is literally the one documented in README.md (“Install the CLI”). Is there a different installation method that I should be using?

I guess I didn’t make myself clear, sorry. I meant that npm -g install @asyncapi/html-template global installation of templates was never supported. Just to imply that it is not a bug that generator cannot access a global template. I’m gonna try to enable support this week https://github.com/asyncapi/generator/issues/482#issuecomment-792601786