When creating an NextJS app using the CLI, one can choose --use-npm
when running npx create-next-app
. When running it without arguments (ie in interactive mode) it doesn’t ask about this.
The help page says
--use-npm
Explicitly tell the CLI to bootstrap the app using npm
and if I use it, then it changes tsconfig.json
to
"paths": {
"--use-npm": ["./src/*"]
}
instead of
"paths": {
"@/*": ["./src/*"]
}
Question
What is the purpose of --use-npm
?
2
Answers
I have found the problem and solution.
The command I ran was
which should have been
For some reason
create-next-app
doesn't have--no-import-alias
which would have been very useful.create-next-app
has this line in the source code to determine whether to usenpm
,pnpm
oryarn
based on the provided flags:If you don’t use an explicit flag then the
getPkgManager
function looks to see if "yarn" or "pnpm" exists in thenpm_config_user_agent
environment variable and defaults tonpm
otherwise. (source)So interactive mode is just defaulting to
npm
.