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

cdktf init fails at npm install (NODE_ENV is not recognized) #198

Closed
rraziel opened this issue Jul 17, 2020 · 18 comments
Closed

cdktf init fails at npm install (NODE_ENV is not recognized) #198

rraziel opened this issue Jul 17, 2020 · 18 comments
Labels
bug Something isn't working windows

Comments

@rraziel
Copy link
Contributor

rraziel commented Jul 17, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

0.0.11 and the typescript template

Debug Output

Figure it's short enough to be here (just few lines):

$ cdktf init --template="typescript" --local
Note: By supplying '--local' option you have chosen local storage mode for storing the state of your stack.
This means that your Terraform state file will be stored locally on disk in a file 'terraform.tfstate' in the root of your project.

We will now setup the project. Please enter the details for your project.
If you want to exit, press ^C.

Project Name: (default: 'tfcdk')
Project Description: (default: 'A simple getting started project for cdktf.')
'NODE_ENV' is not recognized as an internal or external command,
operable program or batch file.

<cut command line options for cdktf displayed>

Error: Command failed: NODE_ENV=development npm install  cdktf@^0.0.11 constructs@^3.0.0
    at checkExecSyncError (child_process.js:630:11)
    at execSync (child_process.js:666:15)
    at installDeps (path\to\npm\node_modules\cdktf-cli\templates\typescript\.hooks.sscaff.js:30:3)

Expected Behavior

No error when doing an init

Actual Behavior

Init fails at the npm install step

Steps to Reproduce

npm i cdktf -g
cdktf init --template="typescript" --local

Important Factoids

Running on Windows 10, Node 12.16.0

@rraziel rraziel added the bug Something isn't working label Jul 17, 2020
@rraziel
Copy link
Contributor Author

rraziel commented Jul 17, 2020

Note: manually doing npm i cdktf@^0.0.11 constructs@^3.0.0 works fine though (should probably be a --save-dev too?)

@Satak
Copy link

Satak commented Jul 17, 2020

Same problem here

@Satak
Copy link

Satak commented Jul 17, 2020

This line I guess:

execSync(`NODE_ENV=development npm install ${devDep} ${deps.join(' ')}`, { stdio: 'inherit' });

@skorfmann
Copy link
Contributor

skorfmann commented Jul 17, 2020

Thanks for reporting the bug. I'll check how to fix this for windows.

Generally, #201 should be implemented to prevent similar platform dependent issues.

@skorfmann
Copy link
Contributor

This line I guess:

execSync(`NODE_ENV=development npm install ${devDep} ${deps.join(' ')}`, { stdio: 'inherit' });

Yes 👍 do you know how to achieve the same desired behavior on windows?

@Satak
Copy link

Satak commented Jul 17, 2020

Yes 👍 do you know how to achieve the same desired behavior on windows?

Maybe best would be to use https://www.npmjs.com/package/cross-env
and execute it with cross-env

execSync(`cross-env NODE_ENV=development npm install ${devDep} ${deps.join(' ')}`, { stdio: 'inherit' });

@Satak
Copy link

Satak commented Jul 17, 2020

Next problem is yarn, which I don't have, is it mandatory or it should init without yarn?

Error:

'yarn' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! terraform-vm-test@1.0.0 build: `yarn get && tsc`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the terraform-vm-test@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xxx\AppData\Roaming\npm-cache\_logs\2020-07-17T11_25_51_330Z-debug.log
cdktf init [OPTIONS]

@skorfmann
Copy link
Contributor

Next problem is yarn, which I don't have, is it mandatory or it should init without yarn?

Error:


'yarn' is not recognized as an internal or external command,

operable program or batch file.

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! terraform-vm-test@1.0.0 build: `yarn get && tsc`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the terraform-vm-test@1.0.0 build script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.



npm ERR! A complete log of this run can be found in:

npm ERR!     C:\Users\xxx\AppData\Roaming\npm-cache\_logs\2020-07-17T11_25_51_330Z-debug.log

cdktf init [OPTIONS]

No, yarn isn't mandatory for normal usage.

It's only required for contributions to this repo, since we are using yarn workspaces

@rraziel
Copy link
Contributor Author

rraziel commented Jul 17, 2020

I'm a bit surprised the NODE_ENV=development is even there, that would be some kind of workaround for environments where someone would have set NODE_ENV=production I think?
Since the default is development, shouldn't this code simply do an npm install?

@skorfmann
Copy link
Contributor

I'm a bit surprised the NODE_ENV=development is even there, that would be some kind of workaround for environments where someone would have set NODE_ENV=production I think?

Since the default is development, shouldn't this code simply do an npm install?

It's set to production, since the cli uses https://github.com/vadimdemedes/ink and that's the recommended setting to suppress internal error messages.

@rraziel
Copy link
Contributor Author

rraziel commented Jul 17, 2020

I'm a bit surprised the NODE_ENV=development is even there, that would be some kind of workaround for environments where someone would have set NODE_ENV=production I think?
Since the default is development, shouldn't this code simply do an npm install?

It's set to production, since the cli uses https://github.com/vadimdemedes/ink and that's the recommended setting to suppress internal error messages.

I'm not sure I'm following, the code that causes the error is executing NODE_ENV=development npm install?
Or are you saying ink sets it to production so you have to set it back to development when running npm install?

Edit: just to be clear, it looks like it's simply doing a npm install of 2 dependencies (which should probably be dev dependencies too), while setting NODE_ENV to production means it will not install devDependencies from the package.json (except the package.json has no dependencies yet since init just created it)

@skorfmann
Copy link
Contributor

Could you give cdktf-cli@next a shot? (npm install -g cdktf-cli@next) It should fix the init issues on Windows

@skorfmann
Copy link
Contributor

Or are you saying ink sets it to production so you have to set it back to development when running npm install?

We do set it to production as ink is recommending it. And yes, you're right - for the npm install we do want to install dev dependencies. These are omitted when NODE_ENV=production.

@rraziel
Copy link
Contributor Author

rraziel commented Jul 17, 2020

Could you give cdktf-cli@next a shot? (npm install -g cdktf-cli@next) It should fix the init issues on Windows

Just tested now, it works.

@skorfmann
Copy link
Contributor

Released in 0.0.12

@colvint
Copy link

colvint commented Sep 4, 2020

Awesome tool here! Nice touch on the auto-generated help too 👍

Changing yarn to npm in package.json:

{
  "scripts": {
     ...
    "build": "npm run get && tsc"
    ...
  }
}

Resolved the issue for me. I don't have yarn installed and don't plan to. So for those in the same boat... You can make that change and then run:

npm run build

To generate your typescript constructs.

@skorfmann
Copy link
Contributor

@colvint that's a good point, thanks for the heads-up. I just created a PR to fix this #359

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2022

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working windows
Projects
None yet
Development

No branches or pull requests

4 participants