Is `npm init <package-spec>` same as `npx <package-spec>`?

306 Views Asked by At

The npm-init documentation says npm init <package-spec> is the same as npx <package-spec>:

npm init <package-spec> (same as `npx <package-spec>)

Is that correct? (Ignore the documentation's missing backtick typo.)

If it is correct, why aren't the following two commands equivalent?

npm init docusaurus # works as expected
npx docusaurus      # error: could not determine executable to run
1

There are 1 best solutions below

0
On

The npm-init documentation is wrong on this point (and is also missing a backtick). npm init <package-spec> is NOT the same as npx <package-spec>.

The npm init documentation should be corrected to say:

npm init <package-spec> (same as `npx create-<package-spec>`)

If this correction is applied to the example, you'll find that the following two commands are indeed equivalent:

npm init docusaurus
npx create-docusaurus      # Equivalent

I've filed two issues:

  1. [DOCS] Missing backtick in synopsis of npm-init #5837

  2. [DOCS] Missing 'create-' in synopsis of npm-init #5838