create-react-app
create-react-app copied to clipboard
`npm init react-app` ignores `--template` directive
The commands npx create-react-app
and npm init react-app
behave differently.
Using npx create-react-app my-app --template typescript
correctly creates a React app with the typescript template.
$ npx create-react-app my-app --template typescript
Creating a new React app in /home/user/my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript...
...
Using npm init react-app my-app --template typescript
(as documented at https://create-react-app.dev/docs/getting-started/#npm) does not work correctly. The --template
directive is silently ignored:
$ npm init react-app my-app --template typescript
Creating a new React app in /home/user/my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
...
Environment
Environment Info:
current version of create-react-app: 5.0.0
running from /home/royston/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app
System:
OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 16.14.2 - ~/.volta/tools/image/node/16.14.2/bin/node
Yarn: Not Found
npm: 8.5.0 - ~/.volta/tools/image/node/16.14.2/bin/npm
Browsers:
Chrome: Not Found
Firefox: Not Found
npmPackages:
react: Not Found
react-dom: Not Found
react-scripts: Not Found
npmGlobalPackages:
create-react-app: Not Found
We're seeing this issue too.
We can't use the npx
method because were using the --scripts-version
tag (ignored by npx) to specify an older version of CRA/react-scripts.
yarn create react-app
will observe the --template
switch (and the --scripts-version
switch) correctly, but that's an extra barrier to entry; not all users will necessarily have Yarn installed.
Adding --
seems to work:
- npm init react-app . --scripts-version=my-scripts --template=my-template
+ npm init react-app . -- --scripts-version=my-scripts --template=my-template
+ npm init react-app . -- --scripts-version my-scripts --template my-template # (equals-sign or space both seem to work)