I'm upgrading to v7 and I'm getting a type error on collectUserIP
import Bugsnag from '@bugsnag/js';
import BugsnagPluginReact from '@bugsnag/plugin-react';
Bugsnag.start({
appType: 'client',
appVersion: GIT_SHA,
apiKey: BUGSNAG_KEY,
autoDetectErrors: true,
releaseStage: ENVIRONMENT,
enabledReleaseStages: ['prod', 'qa', 'active'],
collectUserIp: false,
redactedKeys: [/token/i, /password/i, /name/i, /email/i, /phone/i],
plugins: [new BugsnagPluginReact(React)],
});
Argument of type '{ appType: string; appVersion: string; apiKey: string; autoDetectErrors: true; releaseStage: string; enabledReleaseStages: string[]; collectUserIp: boolean; redactedKeys: RegExp[]; plugins: BugsnagPluginReact[]; }' is not assignable to parameter of type 'string | Config'.
Object literal may only specify known properties, and 'collectUserIp' does not exist in type 'Config'.ts(2345)
The Definition for config appears to be at node_modules/@bugsnag/browser/dist/types/bugsnag-core/common.d.ts
Was collectUserIP removed as an option? if so is there a suggested way to migrate?
Hi @derduher
collectUserIP is still a config option available to be set as part of your config:
https://github.com/bugsnag/bugsnag-js/blob/v7.0.0/packages/browser/types/bugsnag.d.ts#L5
Using your Bugsnag.start method above in our React example app works fine:
https://github.com/bugsnag/bugsnag-js/tree/v7.0.0/examples/react
Are you able to get this example working?
Is this a purely React app you are building?
I'll try and paste a CRA sample repo. If you say that the option still exists, then it may just be a type definition bug (or documentation).
@phillipsam Here is a sample repo created using npx create-react-app cra --use-npm --typescript. I committed the bugsnag additions separate from the initial generations so you can see what I added.
After cloning the repo. npm install then npm run build
You'll see the above pasted type error.
Hi @derduher thanks for the reproduction example!
It looks like you are using the wrong method of including Bugsnag for your module system:
https://docs.bugsnag.com/platforms/javascript/react/#basic-configuration
Currently the example is using:
import Bugsnag from '@bugsnag/js'
import BugsnagPluginReact from '@bugsnag/plugin-react'
If you remove these two lines and replace with:
var Bugsnag = require('@bugsnag/js')
var BugsnagPluginReact = require('@bugsnag/plugin-react')
This then compiles correctly.
@phillipsam Although they compile they lose all type safety as they now register as type 'any'. I've updated my example to point this out. The option 'asdf' is not valid and should not compile.
import is the correct method in create react app and require is generally frowned upon. As create react app is one of the most popular ways to create a react app you are likely to encounter this issue being filed by users again.
I think the right thing to do here would be to fix the typedef.
Bugsnag is of type UniversalBugsnagStatic https://github.com/bugsnag/bugsnag-js/blob/next/packages/js/types.d.ts#L9
Your dist code appears to be including the typedef at https://github.com/bugsnag/bugsnag-js/blob/next/packages/core/types/bugsnag.d.ts#L4
instead of the typedef here
https://github.com/bugsnag/bugsnag-js/blob/next/packages/browser/types/bugsnag.d.ts#L9
note the different acceptable config types
@derduher thanks! Looks like we have missed an update in our changes for v7. This should be start instead of init:
https://github.com/bugsnag/bugsnag-js/blob/47fbd9ed3d9aaf2c03ad61dd0289f536ea25341e/packages/js/types.d.ts#L5
We will look at getting this fixed.
Fixed in v7.0.2
Thank you!