How to disable nextjs telemetry ? I dont want it in my apps
npx next telemetry --disable
I just now find this page
npx next telemetry --disable
Apparently this only disables telemetry on the current machine (by writing config to ~/.config/nextjs-nodejs/config.json
).
According to https://nextjs.org/telemetry I have the following options to disable telemetry:
npx next telemetry disable
every time in production which is not convenientNEXT_TELEMETRY_DISABLED=1
variable (seems it doesn't work for me)Why wouldn't put something like telemetry: false
line to next.config.json file? It's better place for the option
This whole telemetry thing is pretty twisted to be honest.
For starters: its crazy opaque. You should _definitely_ ask for consent beforehands. Upon the first dev
or build
execution of a project, just ASK if its fine to collect that data. Its crazy that I even need to suggest such a behaviour.
Second: Its absolutely against all conventions how this needs to be disabled. I never encountered a project that would need a dev to run an npx command which does unknown voodoo on my machine to disable something in my current project. The command does not run when react has not been installed in the current project. Whut?!
The recently added ENV var option seems to work for me, but its only mentioned in a single line at the very bottom of a long page trying to sell telemetry to me and then telling me how to use that npx stuff to disable it.
The ENV var way should be communicated FIRST, since its project related. The npx way may be communicated afterwards since its a global setting.
Also, I agree with nlevchuk - this should definitely go to next.config - otherwise you just spill possible options across several places, some are in the config file, some need to be passed as env vars - thats just confusing.
Telemetry has been discussed in-depth on the RFC and there is a lot of prior art: https://github.com/zeit/next.js/issues/8442
@timneutkens I don't see any mention of including a telemetry: false
type flag in the config file in the prior discussions. Do you know if that has been discussed somewhere?
Neither the npx
nor the environment variable routes seem to work for disabling telemetry on Firebase (firebase functions). How to disable telemetry on firebase?
Has a feature request been submitted for disabling telemetry via the next config file? I feel this is the most straightforward and sensible solution; preceding comments seem to support this sentiment. I don't mind writing up an RFC if this hasn't been addressed.
Other than user's config.json
and environment variable, you can also disable telemetry by either:
Block telemetry in firewall.
Just block telemetry.nextjs.org
in your hosts or iptables.
Use patch-package to disable nextjs telemetry postPayload() method.
If you want to use patch-package:
Open /node_modules/next/dist/telemetry/post-payload.js
.
Note that this is a compiled js. It's one concatenated long line.
Replace:
exports._postPayload=_postPayload;
with
exports._postPayload=function(){};
npx patch-package next
. It will create a patch file in /patches
folder.In my case it creates next+9.4.4.patch
with the following content:
diff --git a/node_modules/next/dist/telemetry/post-payload.js b/node_modules/next/dist/telemetry/post-payload.js
index 6b3e5d1..fc2e15c 100644
--- a/node_modules/next/dist/telemetry/post-payload.js
+++ b/node_modules/next/dist/telemetry/post-payload.js
@@ -1,4 +1,4 @@
-"use strict";exports.__esModule=true;exports._postPayload=_postPayload;var _asyncRetry=_interopRequireDefault(require("next/dist/compiled/async-retry"));var _nodeFetch=_interopRequireDefault(require("next/dist/compiled/node-fetch"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _postPayload(endpoint,body){return(0,_asyncRetry.default)(()=>(0,_nodeFetch.default)(endpoint,{method:'POST',body:JSON.stringify(body),headers:{'content-type':'application/json'},timeout:5000}).then(res=>{if(!res.ok){const err=new Error(res.statusText);err.response=res;throw err;}}),{minTimeout:500,retries:1,factor:1}).catch(()=>{// We swallow errors when telemetry cannot be sent
+"use strict";exports.__esModule=true;exports._postPayload=function(){};var _asyncRetry=_interopRequireDefault(require("next/dist/compiled/async-retry"));var _nodeFetch=_interopRequireDefault(require("next/dist/compiled/node-fetch"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _postPayload(endpoint,body){return(0,_asyncRetry.default)(()=>(0,_nodeFetch.default)(endpoint,{method:'POST',body:JSON.stringify(body),headers:{'content-type':'application/json'},timeout:5000}).then(res=>{if(!res.ok){const err=new Error(res.statusText);err.response=res;throw err;}}),{minTimeout:500,retries:1,factor:1}).catch(()=>{// We swallow errors when telemetry cannot be sent
})// Ensure promise is voided
.then(()=>{},()=>{});}
//# sourceMappingURL=post-payload.js.map
\ No newline at end of file
The patch-package solution only disable sending telemetry. The telemetry itself is still created and stored somewhere in your machine.
It's just temporary solution until we can disable telemetry by project's local next.config.json
or something.
@timneutkens I dunno, but the time frame from RFC to 'merged' in #8442 was literally 7 days. I don't really think any comments were taken into consideration.
I didn't know that next.js was sending anything out until I randomly saw these messages in the build logs. This should be more prominent and very likely OPT-IN instead of opt out.
Most helpful comment
This whole telemetry thing is pretty twisted to be honest.
For starters: its crazy opaque. You should _definitely_ ask for consent beforehands. Upon the first
dev
orbuild
execution of a project, just ASK if its fine to collect that data. Its crazy that I even need to suggest such a behaviour.Second: Its absolutely against all conventions how this needs to be disabled. I never encountered a project that would need a dev to run an npx command which does unknown voodoo on my machine to disable something in my current project. The command does not run when react has not been installed in the current project. Whut?!
The recently added ENV var option seems to work for me, but its only mentioned in a single line at the very bottom of a long page trying to sell telemetry to me and then telling me how to use that npx stuff to disable it.
The ENV var way should be communicated FIRST, since its project related. The npx way may be communicated afterwards since its a global setting.
Also, I agree with nlevchuk - this should definitely go to next.config - otherwise you just spill possible options across several places, some are in the config file, some need to be passed as env vars - thats just confusing.