Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm init - how to confirm the "Is this ok?" question #14257

Closed
retan opened this issue Oct 12, 2016 · 53 comments
Closed

npm init - how to confirm the "Is this ok?" question #14257

retan opened this issue Oct 12, 2016 · 53 comments

Comments

@retan
Copy link

retan commented Oct 12, 2016

I'm opening this issue because:

It's not a big issue but it a bit irritating. When I run the npm init everything goes fine. The package.json is created but I have no idea how to confirm the "Is this ok? (yes)" question. I expect that after confirmation the process should stop / terminate itself. I tried hitting Enter, typing "yes" and hitting Enter, typing "y" and hitting Enter but I only get some new lines.

Running on , using git bash.

supporting information:

  • npm -v prints: 3.7.3
  • node -v prints: v5.9.1
  • npm config get registry prints: https://registry.npmjs.org/
  • OS: Windows 10 pro 64bit
  • Using: git bash
@ChiralCarbon
Copy link

Same problem!Please help

@retan
Copy link
Author

retan commented Oct 18, 2016

I determined it happens only in git bash. In the default windows command line it works as expected.
I'm not sure if that is a git bash or npm issue then?

@slamma009
Copy link

Yeah, it works perfectly fine in default windows CMD prompt. Thanks for that retan.

@legodude17
Copy link
Contributor

Do all of the other questions in npm init work? This is either an issue with git bash or read. I am leaning towards git bash.

@retan
Copy link
Author

retan commented Nov 7, 2016

@legodude17 it seems all the others do work. If I press Enter when the Is this ok? (yes) questions is displayed, a (correct) package.json file is created but the process does not stop. If I type no and press Enter then Aborted. is displayed but the process does not stop either.

@legodude17
Copy link
Contributor

Do you have a file called ~/.npm-init.js?

@retan
Copy link
Author

retan commented Nov 9, 2016

@legodude17 Where exactly? It's not in my project in any case.

@legodude17
Copy link
Contributor

In you home directory, called npm-init.js.

@retan
Copy link
Author

retan commented Nov 9, 2016

No, there's none.
I tested npm init command with a completely empty folder.

@legodude17
Copy link
Contributor

Ok. I looked through the code, the real problem is the init-package-json package. Also, the Is this ok? question is the only one that init-package-json asks instead of letting promzard do it. How about you try running node -e "read({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {if (!ok || ok.toLowerCase().charAt(0) !== 'y') { console.log('Aborted.'); } else { console.log('Yay!');} })"? Does that work correctly?

@legodude17
Copy link
Contributor

Upon looking at promzard, my guess is that read() errored somehow and then it just hung, because that line doesn't actually handle errors. Probably git bash does something with that prompt.

@legodude17
Copy link
Contributor

Issued a PR to fix that in init-package-json. npm/init-package-json#68

@retan
Copy link
Author

retan commented Nov 9, 2016

@legodude17 I've run that command in git bash and the output was:
bash: !ok: event not found

@legodude17
Copy link
Contributor

Now I am very confused. What do you think @kenany or @zkat? It looks like the command was parsed wrong. Try opening the node REPL and pasting in

read({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {
  if (!ok || ok.toLowerCase().charAt(0) !== 'y') {
    console.log('Aborted.');
  } else {
    console.log('Yay!');
  }
})

@retan
Copy link
Author

retan commented Nov 9, 2016

@legodude17 sorry but I'm relatively new to node. What is REPL?

@legodude17
Copy link
Contributor

Just run node with no arguments and you can then just enter random code into the prompt. Paste the code above at the >. 😄

@retan
Copy link
Author

retan commented Nov 9, 2016

OK. 😆
This is what I've got:

$ node
> read({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {
...   if (!ok || ok.toLowerCase().charAt(0) !== 'y') {
.....     console.log('Aborted.');
.....   } else {
.....     console.log('Yay!');
.....   }
... })
ReferenceError: read is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
    at REPLServer.Interface._ttyWrite (readline.js:827:14)

@legodude17
Copy link
Contributor

Oh right. I forgot. Third try is the charm. Go to empty directory, run npm install read, then node, then paste in

require('read')({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {
  if (!ok || ok.toLowerCase().charAt(0) !== 'y') {
     console.log('Aborted.');
   } else {
    console.log('Yay!');
  }
})

@retan
Copy link
Author

retan commented Nov 10, 2016

Here's the output after hitting Enter key:

> require('read')({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {
...   if (!ok || ok.toLowerCase().charAt(0) !== 'y') {
.....      console.log('Aborted.');
.....    } else {
.....     console.log('Yay!');
.....   }
... })
Is this ok? (yes) undefined
>
>
Yay!

But now if I try to type some answer something strange is going on. Here I tried to type y but got yy. And as you see there is a ReferenceError.

> require('read')({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {
...   if (!ok || ok.toLowerCase().charAt(0) !== 'y') {
.....      console.log('Aborted.');
.....    } else {
.....     console.log('Yay!');
.....   }
... })
Is this ok? (yes) undefined
> yy
ReferenceError: y is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
    at REPLServer.Interface._ttyWrite (readline.js:827:14)
>
Yay!

Here I tried to type yes but got yyeess

> require('read')({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) {
...   if (!ok || ok.toLowerCase().charAt(0) !== 'y') {
.....      console.log('Aborted.');
.....    } else {
.....     console.log('Yay!');
.....   }
... })
Is this ok? (yes) undefined
> yyeess
ReferenceError: yes is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
    at REPLServer.Interface._ttyWrite (readline.js:827:14)
>
Yay!

@legodude17
Copy link
Contributor

So the command worked, but the way the REPL works, it was interpreted once by the read(1), and then again by the REPL itself. This is actually kind of a bug with the REPL. Do you still have this issue after updating to the latest npm?

@retan
Copy link
Author

retan commented Nov 11, 2016

I've just installed the lasted node.js.

$ npm -v
3.10.8

Thee result of your code in git bash is exactly the same.

@legodude17
Copy link
Contributor

Does npm init work the way it should now in git bash.

@retan
Copy link
Author

retan commented Nov 15, 2016

No, it does not.
I behaves exactly the same as described at the beginning.

@retan
Copy link
Author

retan commented Nov 15, 2016

I've just tried to run npm init --verbose. Maybe this will give you some idea. As before - the command did not exit after confirmation:

$ npm init --verbose
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'init',
npm verb cli   '--verbose' ]
npm info using npm@3.10.8
npm info using node@v6.9.1
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (test2) test2test
version: (1.0.0)
description: test
entry point: (index.js) test.js
test command:
git repository:
keywords: some test key words
author: me
license: (ISC) UNLICENSED
About to write to D:\xampp\htdocs\test2\package.json:

{
  "name": "test2test",
  "version": "1.0.0",
  "description": "test",
  "main": "test.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "some",
    "test",
    "key",
    "words"
  ],
  "author": "me",
  "license": "UNLICENSED"
}


Is this ok? (yes) y
npm info init written successfully
npm verb exit [ 0, true ]

@legodude17
Copy link
Contributor

According to the log, it exited. Does it still hang?

@retan
Copy link
Author

retan commented Nov 15, 2016

Yes it does.

@legodude17
Copy link
Contributor

That is very strange, because it says it exited. @kenany, any thoughts?

@vemvemvem
Copy link

Same problem just now. New to Node & Gitbash. Would love if it worked.

@retan
Copy link
Author

retan commented Nov 22, 2016

@vemvemvem My advice until it get fixed - just use the regular windows command line for npm init. Ever since I came across this problem (with npm init in git bash) I switched to command line and I hate to admit... it works better with node than git bash in many respects (output coloring, additional info from some scripts, etc.).

@legodude17
Copy link
Contributor

I still don't get how it was saying it exited and then not exiting.

On Tue, Nov 22, 2016 at 10:48 AM, Oliwer notifications@github.com wrote:

@vemvemvem https://github.com/vemvemvem My advice until it get fixed -
just use the regular windows command line for npm init. Ever since I came
across this problem (with npm init in git bash) I switched to command
line and I hate to admit... I works better with node than git bash in many
respects (output coloring, additional info from some scripts, etc.).


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#14257 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AKr56LV_XGzFT8uWKV7dUhfL44KTgWnsks5rAzkXgaJpZM4KUpXH
.

@retan
Copy link
Author

retan commented Nov 23, 2016

@legodude17 Maybe you should install git bash and test it yourself. Maybe there's something running in the background that doesn't respond the way that git bash expects (it's just a wild guess).

@legodude17
Copy link
Contributor

legodude17 commented Nov 23, 2016 via email

@retan
Copy link
Author

retan commented Nov 25, 2016

npm init hangs.
npm init -y does not hang.

@Philneeves
Copy link

Hi retan I had this problem and in fact you just press ctrl + C and it takes you back to the command line in git bash in the directory you would have set up for this

@vemvemvem
Copy link

@retan @legodude17 @Philneeves

Both methods work. "npm init -y" as well as "npm init" & CTR + C while screen hangs. Thanks guys !

@retan
Copy link
Author

retan commented Nov 25, 2016

Of course you can kill it. That does not change the fact something is not working here as expected, which is confusing.

@legodude17
Copy link
Contributor

I agree with @vemvemvem and @retan. You can kill it, but it should exit on its own. I will look into this more soon.

@ghost
Copy link

ghost commented Dec 2, 2016

You should run this command and restart git-bash.

$ echo alias npm=\"winpty npm.cmd\" >> ~/.bashrc

@retan
Copy link
Author

retan commented Dec 3, 2016

@hyeonsig What does that command do?

@legodude17
Copy link
Contributor

It runs npm with winpty always. IDK what winpty is, so ask @hyeonsig for that.

@retan
Copy link
Author

retan commented Dec 7, 2016

@hyeonsig Is this what you meant? https://github.com/rprichard/winpty
Sorry, but it sounds a bit fishy to mee. I don't like the part about the "hidden console window" at all. I'm not an expert, but isn't it a security risk?

@Philneeves
Copy link

Hi guys sorry for my comment before about ctrl + c as of course that does just break you out of it if it is hanging. I'd only just started using it and wasn't aware. The issue is in fact with git bash and I've switched now to Windows Powershell for my git and that works perfectly.

@fabricepallaud
Copy link

Hmm still no fix for this?

@Philneeves
Copy link

It's a git bash issue, just don't use git bash

@jamesbarrett95
Copy link

jamesbarrett95 commented Apr 4, 2017

Experiencing the same issue in Git Bash. Despite the package.json being created, the process still runs. Just do a CTRL + C to terminate the process.

@ob-ivan
Copy link

ob-ivan commented May 3, 2017

Still having the issue here. Thanks to this thread for work-arounds.

@WaffleSouffle
Copy link

Have same issue with npm v4.5.0 on node v.7.10.0 compiled on Windows 10 with VS2017 Community Edition (seems to use VS2015 toolkit) under MSYS2, MINGW64, and Cygwin bash shells.

Problematic for writing shell scripts that include an npm init interactive step (at the moment I just make them non-interactive, since otherwise CTRL+C will exit the enclosing script).

@stiofand
Copy link

stiofand commented May 6, 2017

I can confirm this error on git-bash too. However, I also use embedded git bash in IntelliJ idea for my projects, and it doesn't hang there which is strange, since its still only calling the same executable. No issues on Powershell, Windows Bash (beta) or Command Line.

@JustinMorgan
Copy link

I have the same experience as @stevematdavies, except I'm using embedded git bash in Visual Studio Code (Insiders, which is the unstable/edge branch of VSC). The standalone git bash hangs, the embedded version doesn't, but they're both running bash.exe from the same file. Running bash --version in either console gives the same output:

GNU bash, version 4.4.12(1)-release (x86_64-pc-msys)

@legodude17
Copy link
Contributor

legodude17 commented Jun 2, 2017

I think it might be something to do with the terminal, not the command line. Git bash might doing something odd.

@youssef-from-udacity
Copy link

i think you can just type c + ctrl then back to normal

@npm-robot
Copy link

We're closing this support issue as it has gone three days without activity. The npm CLI team itself does not provide support via this issue tracker, but we are happy when users help each other here. In our experience once a support issue goes dormant it's unlikely to get further activity. If you're still having problems, you may be better served by joining package.community and asking your question there.

For more information about our new issue aging policies and why we've instituted them please see our blog post.

@babul101
Copy link

babul101 commented Jul 27, 2017

npm init -y totally worked.
It helped me to create package.json file without getting into the loop

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests