next.js: Using npx to opt-out of telemetry when using yarn pnp will fail

See original bug report below.

The page https://nextjs.org/telemetry suggest that telemetry can be disabled using npx next telemetry disable in the root of a project. This is similar to running the next binary that’s present in node_modules directly.

When using Yarn PnP (which is default for Yarn 2), npx next telemetry disable is going to try to run next using npm, and without pnp resolution (read: it will look for node_modules when resolving requires, instead of the hoisted location on disk).

Solution

Update the documentation to have the yarn commands listed as well:

npx next telemetry disable

# Or when using yarn
yarn next telemetry disable

(note: yarn next is, in this case similar to npx next, but it’s not exactly the same. Something to keep in mind).


What version of Next.js are you using?

10.0.5

What version of Node.js are you using?

12.20.1

What operating system are you using?

Windows

Describe the Bug

See steps to reproduce.

When using Yarn 2, it’s impossible to opt-out of telemetry on a permanent basis, because (assumption) the tooling is looking for react and react-dom in the non-pnp node_modules location.

It then continues giving an erroneous non-actionable error:

The module 'react' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install react'
The module 'react-dom' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install react-dom'
Cannot find module 'react'

After this occurs, it can be resolved by switching to Yarn 1:

yarn set version classic
yarn install

npx next telemetry disable

The expected behaviour is then observed.

Expected Behavior

$ npx next telemetry disable
Your preference has been saved.

Status: Disabled

You have opted-out of Next.js' anonymous telemetry program.
No data will be collected from your machine.
Learn more: https://nextjs.org/telemetry

To Reproduce

Following these steps, but then with --use-yarn.

npx create-next-app nextjs-blog --use-yarn --example "https://github.com/vercel/next-learn-starter/tree/master/learn-starter"

yarn set version berry
yarn install

Afterwards

npx next telemetry disable

Happy to run any more commands, but I think I’ve pointed out where I assume this error lies.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@SleeplessByte, we pushed changes to the docs. They will be up to date in the next release 🙏

Oh, it seems our website is still closed source! @leerob can you please update this?

I’d like to understand why Yarn 2 is erroring here, as we’re using require.resolve:

The command @SleeplessByte is showing is using npx which doesn’t setup the PnP context, it works just fine with yarn next telemetry disable

$ yarn next telemetry disable
Next.js' telemetry collection is already disabled.

Status: Disabled

You have opted-out of Next.js' anonymous telemetry program.
No data will be collected from your machine.
Learn more: https://nextjs.org/telemetry
npx next telemetry disable

You ran npx. As a result, the PnP runtime isn’t loaded. Don’t mix Yarn and npm 🙂

Works:

yarn next telemetry disable