Error when setting up Vite React project: npm warns about unknown config '--template'

I’m having trouble setting up a new React project with Vite. When I run the command to create the app, I get a weird warning about an unknown config.

Here’s what I typed in the terminal:

npm create vite@latest my-cool-app -- --template react -y

But then I see this message:

npm WARN Unknown cli config '--template'

The app doesn’t get created like it should. I’m using Node v22.14.0 and npm v11.2.0 on Windows 10 Pro.

I even tried without the double dashes, but no luck:

npm create vite@latest my-cool-app --template react

Same problem. How can I make this work? I just want to set up a Vite React project quickly without having to answer a bunch of questions about frameworks and stuff. Any ideas?

I encountered a similar issue recently. The problem lies in how npm interprets the command-line arguments. For Vite, it’s better to use ‘npx’ instead of ‘npm create’. Try this command:

npx create-vite@latest my-cool-app --template react

This should work without any warnings. The ‘npx’ command ensures you’re using the latest version of create-vite and handles the arguments correctly. If you still face issues, make sure your Node.js and npm versions are up to date. As a last resort, you could also consider using the Vite CLI directly:

npm init vite@latest my-cool-app – --template react

This syntax is slightly different but achieves the same result. Let me know if you need any further assistance!

I’ve run into this exact problem before, and it can be frustrating. The issue is actually with how npm handles the command-line arguments for Vite. A workaround that’s worked consistently for me is using the ‘yarn’ package manager instead of npm. Here’s what you can do:

First, install yarn globally if you haven’t already:

npm install -g yarn

Then, create your Vite React project with this command:

yarn create vite my-cool-app --template react

This method bypasses the npm warning and creates the project smoothly. If you prefer sticking with npm, you could also try:

npm init vite@latest my-cool-app – --template react

The double dashes here are crucial. They separate npm’s own options from the arguments passed to the create-vite script.

Hope this helps you get your project up and running!

hey there! i had the same issue. try using ‘npm init vite@latest my-cool-app’ first, then choose react when prompted. if that doesn’t work, you could also use ‘yarn create vite my-cool-app --template react’ (install yarn if u don’t have it). hope this helps!