skip to Main Content

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


  1. Chosen as BEST ANSWER

    I have found the problem and solution.

    The command I ran was

    npx create-next-app --typescript --tailwind --app --src-dir --import-alias --use-npm --no-eslint
    

    which should have been

    npx create-next-app --typescript --tailwind --app --src-dir --import-alias '@/*' --use-npm --no-eslint
    

    For some reason create-next-app doesn't have --no-import-alias which would have been very useful.


  2. create-next-app has this line in the source code to determine whether to use npm, pnpm or yarn based on the provided flags:

    const packageManager = !!program.useNpm
      ? 'npm'
      : !!program.usePnpm
      ? 'pnpm'
      : !!program.useYarn
      ? 'yarn'
      : getPkgManager()
    

    If you don’t use an explicit flag then the getPkgManager function looks to see if "yarn" or "pnpm" exists in the npm_config_user_agent environment variable and defaults to npm otherwise. (source)

    So interactive mode is just defaulting to npm.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search