Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run - /usr/bin/env: ‘node\r’: Permission denied #10

Open
msrcodes opened this issue Apr 20, 2021 · 22 comments
Open

Cannot run - /usr/bin/env: ‘node\r’: Permission denied #10

msrcodes opened this issue Apr 20, 2021 · 22 comments
Labels
enhancement New feature or request

Comments

@msrcodes
Copy link

Brief bug description

When trying to run kontent-generate, the binary crashes and fails to run with the error message:

/usr/bin/env: ‘node\r’: Permission denied

Repro steps

  1. Install with yarn global add @kentico/kontent-model-generator or npm i @kentico/kontent-model-generator -g
  2. In a terminal, run:
kontent-generate --projectId=XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX --moduleResolution=ES2015 --codeType=TypeScript
  1. Observe error

Expected behavior

Script should work

Test environment

  • Platform/OS: Ubuntu
  • Node: 15.14.0
  • NVM: 0.37.2

Additional context

running the following command works as a workaround:

node $(which kontent-generate) --projectId=XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX --moduleResolution=ES2015 --codeType=TypeScript
@Enngage
Copy link
Contributor

Enngage commented Apr 20, 2021

Hi @mikaelsrozee ,

This is not an issue with this library - rather there seems to be a problem in your environment and lack of permissions. Did you install node? I'm not very familiar with Linux so I can't really comment on where and how you should setup your permissions, but there is definitely a problem with your CMD accessing Node scripts.

@msrcodes
Copy link
Author

msrcodes commented Apr 20, 2021

Hi @Enngage, thanks for getting back to me quickly.

This isn't an issue with my environment, nor a lack of permissions. My suspicion is that this is due to the library being written using Windows file endings - \r\n.

When a Unix user (be it Mac or Linux) tries to exec the command line tool, their terminal will attempt to run the following:

/usr/bin/env node\r

which will fail, as node\r doesn't exist on my machine

if I were to just run the following command, it would work and load the node REPL

/usr/bin/env node

(and yes, Node is installed on my machine - see my original post)

@Enngage
Copy link
Contributor

Enngage commented Apr 20, 2021

Ah, I see. If I remember correctly, some other user on Linux recommended to add this line -> https://github.com/Kentico/kontent-model-generator-js/blob/c2294c1f33b98728b9590154e9fb84f6619798ee/src/app.ts#L1

It seems to have helped him run this tool under Linux, not really sure what I could do to "fix" this. Feel free to let me know if you have an idea.

@hjfitz
Copy link

hjfitz commented Apr 22, 2021

I'm finding the same issue. The shebang should help, but the carriage returns from Windows aren't playing nicely with my Mac environment.

@Enngage
Copy link
Contributor

Enngage commented Oct 11, 2021

I'm not sure how to improve/fix this, so if anyone has an idea, please let me know.

@owain68
Copy link

owain68 commented Jan 9, 2023

I am having the same problem. It manifests if you install the package using yarn and is indeed to do with windows line endings. I am on a Mac and using "@kontent-ai/model-generator": "^5.9.0".
The issue is explained here with a workaround.

Install crlf yarn add crlf -D

`❯ kontent-generate
env: node\r: No such file or directory

❯crlf --set=LF node_modules/.bin/kontent-generate
CRLF node_modules/.bin/kontent-generate -> LF

❯ kontent-generate
(node:14485) UnhandledPromiseRejectionWarning: Error: Please provide project id using 'projectId' argument

`
So this looks to have temporarily fixed this on my machine for this yarn install.

@Enngage needs to be fixed in the package creation.

To fix it you need to change the line endings. But you need to ensure this happens after each install of packages!

@owain68
Copy link

owain68 commented Jan 9, 2023

@Enngage

Well the executable runs but I am getting a http 403 (not authorized). I suspect the line endings in the code are invalidating the http headers. From the output I can see.

'authorization: bearer ew0K<snip>PRA8\r\n' has \r\n included within the string which would pass an invalid management API key. Is there something we can do here - other than run on a windows machine?

@ItsMeDelanoDev
Copy link

I also really would like to see a solution to this. It is currently blocking us from choosing Kontent AI.

@Enngage Enngage added the enhancement New feature or request label Jan 13, 2023
@Enngage
Copy link
Contributor

Enngage commented Jan 13, 2023

I also really would like to see a solution to this. It is currently blocking us from choosing Kontent AI.

Hi @ItsMeDelanoDev,

We'll investigate internally and test the line endings. I don't have access to Mac, but I'll try to find someone who does. On another note, is there any particular reason you couldn't generate models using this approach https://github.com/kontent-ai/model-generator-js#generate-models-in-code ? It should be quite easy to implement this until there is an official way of running this library on MacOS.

@owain68
Copy link

owain68 commented Jan 13, 2023

@Enngage it might also be an issue on linux as line endings work the same way. You could spin a linux server up somewhere in the cloud to test it too? Not sure how WSL works but that might be a bit quicker to test.

@owain68
Copy link

owain68 commented Jan 13, 2023

@Enngage @ItsMeDelanoDev

I have just tried to generate the models in the code but the same thing happens. Which is not altogether surprising since it uses the same npm packages.

Just to be clear, the error is as follows:

message: 'The Subscription API is not supported in your plan.', requestId: '3782180d8de4bf3a', errorCode: 13, originalError: [AxiosError: Request failed with status code 403] { code: 'ERR_BAD_REQUEST',
but the it is a proper management API key I am presenting but I can see the issue in the the http headers, namely the header has \r\n appended

'authorization: bearer ewXXXXXXXXXXXXXXA8\r\n'

@JiriLojda
Copy link
Member

Hi,
I tried running the generator from terminal on macOS Ventura (M1 pro) without any issues.
43A4454E-A1C1-490E-B6DE-5BC2619F675C

@Nickm615
Copy link

@owain68 This error in particular points to the subscription API key, not the Management API key. My understanding is that this Subscription API is only needed to generate role types, I would suggest setting the exportRoles configuration value to false and see if this fixes the error you are receiving.

@owain68
Copy link

owain68 commented Jan 14, 2023

@Nickm615

I am still getting this error with the following code:

https://gist.github.com/owain68/00dfaaccb5caea65063b4062d21f75ef

@Enngage
Copy link
Contributor

Enngage commented Jan 14, 2023

@Nickm615

I am still getting this error with the following code:

https://gist.github.com/owain68/00dfaaccb5caea65063b4062d21f75ef

What error?

Additionally @JiriLojda found out that the issue only occurs when using yarn rather than npm. Can you guys (@ItsMeDelanoDev, @owain68 ) try using npm?

@owain68
Copy link

owain68 commented Jan 14, 2023

@JiriLojda That's the same set up as my machine. What version of kontent-generator have you installed. I am running

kontent-generate --version
5.9.0

@Enngage
Copy link
Contributor

Enngage commented Jan 14, 2023

@JiriLojda That's the same set up as my machine. What version of kontent-generator have you installed. I am running

kontent-generate --version 5.9.0

@JiriLojda is using this :-)

MicrosoftTeams-image

@owain68
Copy link

owain68 commented Jan 14, 2023

@Enngage I have deleted the npm_modules and reinstalled using npm and this problem does not occur. Unfortunate if you are using Yarn which I am. I had got that far and this workaround helped. But I think I need to also run the crlf against the management-sdk package as I think it is displaying the same issues.

Perhaps you could try install using Yarn and see if you have the same issue.

I have now come up with another problem and will raise an issue.#37

@ItsMeDelanoDev
Copy link

@Enngage Interesting, NPM seems to work indeed! Looks like the API request is only "broken" when installed with yarn.

Thank you for your efforts!

@owain68
Copy link

owain68 commented Jan 19, 2023

@Enngage is this being fixed or we just have to use npm in a separate project? Please close if you are not looking to resolve this issue.

@Enngage
Copy link
Contributor

Enngage commented Jan 19, 2023

We'll probably try addressing this in future and see if we can do something about this I'll keep the issue open so that it's here, but the current recommendation is to use npm on non-windows systems.

@JiriLojda
Copy link
Member

I tried a couple more scenarios all with the latest version of @kontent-ai/model-generator (5.9.0). I tried running the generator from a command line and running it from code using the example (https://gist.github.com/owain68/00dfaaccb5caea65063b4062d21f75ef) provided by @owain68. All cases run on a macOS Ventura M1 pro. The results are:

  • yarn version 3.3.1 installed as a local package running from code -> works
  • yarn version 3.3.1 running from command line using yarn dlx (new versions of yarn (> 1) don't support global packages and the dlx command serves as a replacements and works pretty much like the npx command) -> works
  • yarn version 1.22.19 installed as a local package running from code -> works
  • yarn version 1.22.19 running from command line (installed as a global package) -> doesn't work
  • npm version 8.19.3 (both local and global package) -> works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants