2

After running npm init react-app new-app --template typescript it simply creates a javascript template project, not typescript. I want to create a typescript project using CLI.

Node JS version: 15.9.0
NPM version: 7.0.15

Tahazzot
  • 1,060
  • 2
  • 21
  • Have you tried `npx create-react-app my-app --template typescript`? – Arman Charan Feb 23 '21 at 08:18
  • Of course. It works fine, But why ```npm``` not working. What is the mistake in this command? – Tahazzot Feb 23 '21 at 08:22
  • @ChosenUser Command seems right. Works for me Node JS - 10.16 and npm - 6.14 – Lakshya Thakur Feb 23 '21 at 08:28
  • Npm and npx are two different things. Npm is package manager while npx is package executor https://stackoverflow.com/questions/50605219/difference-between-npx-and-npm – szczocik Feb 23 '21 at 08:28
  • @szczocik My first instinct was that but `npm init `can take an `initializer` which in our case is `react-app` translated to `npx create-react-app` – Lakshya Thakur Feb 23 '21 at 08:29
  • Thank you all of you guys. I got my answer. – Tahazzot Feb 23 '21 at 08:32
  • 1
    [The docs](https://docs.npmjs.com/cli/v7/commands/npm-init) suggest that, in v7, you need `--`: `npm init react-app -- new-app --template typescript`. – jonrsharpe Feb 23 '21 at 08:33
  • @jonrsharpe That's exactly what I am looking for. A big thanks for your time. – Tahazzot Feb 23 '21 at 08:39
  • 1
    Then why have you accepted rustyBucketBay's answer below, which *doesn't* tell you that? It just links to the (wrong!) docs. You don't have to (and shouldn't) accept any answer that's posted, first check that they actually solve your problem. – jonrsharpe Feb 23 '21 at 08:40

1 Answers1

3

Per the docs, in NPM v7:

Any additional options will be passed directly to the command, so npm init foo -- --hello will map to npx create-foo --hello.

This is subtly different to v6, where:

Any additional options will be passed directly to the command, so npm init foo --hello will map to npx create-foo --hello.

Note the additional -- for v7, which in your case would be:

npm init react-app -- new-app --template typescript
jonrsharpe
  • 99,167
  • 19
  • 183
  • 334