Open trueleader opened 2 years ago
Can you give us an example where this occurs?
I normally optOut
in a central place of all projects, as I don´t know which libraries includes telemetry-js.
So before anything else, I do
import PnPTelemetry from "@pnp/telemetry-js";
PnPTelemetry.getInstance().optOut();
As I deployed backend logic to a NodeJS plattform hosted on Azure Function, I got a "window is not defined" error.
Don´t know why this was not happening while developing ... maybe either the local func environment brings a window
object, or VSC defines one in the terminal view
Which PnP packages are you using? As this is indeed intended for front-end packages like the PnP Controls.
The AzureFunction uses @pnp/nodejs and @pnp/sp Frontend much more I moved the code from central project to frontend only and no track request is done
The reason I created the issue: A user should not need to know the internals of the package - as the package itself normally is only used by other packages. The existence of window should be checked first and if not getInstance should either itself throw an error - or declare a private variable to store the instance.
Weird, as these packages don't use this dependency.
Can you check which dependency depends on this in the package-lock.json or yarn.lock file?
Frontend has telemetry-js inside its dependency tree via @pnp/spfx-controls-react
But as said: as this is a transitive dependency and the developer can not know if it is used or not.
If (for example) @pnp/sp
will use @pnp/telemetry-js
in it´s next version - than tracking would be active which must never happen.
Thats why I added telemetry-js in a "business-logic" project to optOut
, so other projects of the app/workspace (all referencing "business-logic") can use every @pnp package without a possibility of activating tracking from accident
The
getInstance
function has a hard dependency to a globalwindow
object Ifwindow
does not exist a 'window is not defined' will be thrown