npm / npm

This repository is moving to: https://github.com/npm/cli

Home Page:http://npm.community

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

retan opened this issue · comments

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

Same problem!Please help

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?

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

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.

@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.

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

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

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

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

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?

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.

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

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

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!');
  }
})

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

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

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)

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!');
  }
})

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!

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?

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.

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

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

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 ]

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

Yes it does.

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

commented

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

@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.).

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
.

@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).

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

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

commented

@retan @legodude17 @Philneeves

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

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

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

You should run this command and restart git-bash.

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

@hyeonsig What does that command do?

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

@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?

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.

Hmm still no fix for this?

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

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.

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

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).

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.

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)

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

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

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.

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