Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Uncaught ReferenceError: __extends is not defined #1527

Closed
plamenkoyovchev opened this issue Apr 8, 2021 · 16 comments
Closed

[BUG] Uncaught ReferenceError: __extends is not defined #1527

plamenkoyovchev opened this issue Apr 8, 2021 · 16 comments

Comments

@plamenkoyovchev
Copy link

plamenkoyovchev commented Apr 8, 2021

Description/Screenshot
I have a react app which is created with create-react-app.
When I create production build of my app and serve it I'm getting the following error:

image
image

The problem exists only when app is build for production. It's working when starting it in development mode.

It's not working even in this demo app: https://github.com/Azure-Samples/application-insights-react-demo
I had to update to 3.0.5 because the older version doesn't have AppInsightsErrorBoundary

Packages

  • "@microsoft/applicationinsights-react-js": "^3.0.5",
  • "@microsoft/applicationinsights-web": "^2.6.1",
  • "react": "^16.13.1"

Steps to Reproduce

  • create app with create-react-app
  • wrap some component with the AppInsightsErrorBoundary component
  • npm run build
  • serve -s build
@MSNev
Copy link
Collaborator

MSNev commented Apr 8, 2021

Can I assume that you are using a bundling package (like webpack)?

I believe this is a duplicate issue and a workaround for the bundling is included in #1281, the workaround included for the webpack chunking issue is below (taken from #1281)

config.plugins.push(
  new webpack.ProvidePlugin({
    '__assign': ['@microsoft/applicationinsights-shims', '__assignFn'],
    '__extends': ['@microsoft/applicationinsights-shims', '__extendsFn']
    // '__assign': ['tslib', '__assign'],
    // '__extends': ['tslib', '__extends']
  })

And further details

@MSNev
Copy link
Collaborator

MSNev commented Apr 15, 2021

Closing as believe the workaround addresses the issue

@MSNev MSNev closed this as completed Apr 15, 2021
@MSNev
Copy link
Collaborator

MSNev commented Apr 21, 2021

v2.6.2 will also fix these type of issue moving forward as we will be including our own version directly, rather than relying on the TsLib (or shims) versions being included by packagers

@parthopdas
Copy link

@MSNev

updating to v2.6.2 of applicationinsights-web didn't work unfortunately.

with v2.6.2 of applicationinsights-web ie digitalpalitools/web-ui@42c55ac i get the following error
image

however things are fine after applying your provideplugin workaround, in addition to the above ie digitalpalitools/web-ui@b6b8970

@mmarshad
Copy link

@parthopdas
I'm experiencing the same problem as upgrade did not work for me either. but I'm using the create-react-app template and therefore did not have webpack config file. How can I apply the patch in my code as I only have the package.json and tsconfig.json files.

@parthopdas
Copy link

parthopdas commented Apr 26, 2021

@mmarshad i am using craco which lets you hijack into webpack config of a CRA app- you can refer to https://github.com/digitalpalitools/web-ui/ on how to do it.

@mmarshad
Copy link

@parthopdas : Thanks for response, I'm afraid I can't use that.

@sommesh
Copy link

sommesh commented Apr 26, 2021

Current version:
"@microsoft/applicationinsights-react-js": "^3.1.0",
"@microsoft/applicationinsights-shims": "^2.0.0",
"@microsoft/applicationinsights-web": "^2.6.2",

And added the import in base index
import '@microsoft/applicationinsights-shims';
But still, getting the error:

ReactPlugin.js:7 Uncaught ReferenceError: __extends is not defined
at ReactPlugin.js:7
at Module../node_modules/@microsoft/applicationinsights-react-js/dist-esm/ReactPlugin.js (ReactPlugin.js:87)

Any workaround or fix?

@MSNev
Copy link
Collaborator

MSNev commented Apr 26, 2021

PR for bumping versions to consume v2.6.2 and shims v2.0.0 is out #1552

@MSNev
Copy link
Collaborator

MSNev commented Apr 26, 2021

React v3.1.1 and ReactNative v2.3.1 are now published to NPM

@TaranbirBhullar
Copy link

@MSNev We recently upgraded to the following packages

+-- @microsoft/applicationinsights-react-js@3.1.1
  | +-- @microsoft/applicationinsights-common@2.6.2
  | | `-- @microsoft/applicationinsights-shims@2.0.0  deduped 
  | +-- @microsoft/applicationinsights-core-js@2.6.2
  | | `-- @microsoft/applicationinsights-shims@2.0.0  deduped 
  | `-- @microsoft/applicationinsights-shims@2.0.0 
  `-- @microsoft/applicationinsights-web@2.6.2
    +-- @microsoft/applicationinsights-analytics-js@2.6.2     
    | `-- @microsoft/applicationinsights-shims@2.0.0  deduped 
    +-- @microsoft/applicationinsights-channel-js@2.6.2       
    | `-- @microsoft/applicationinsights-shims@2.0.0  deduped 
    +-- @microsoft/applicationinsights-dependencies-js@2.6.2  
    | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
    +-- @microsoft/applicationinsights-properties-js@2.6.2
    | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
    `-- @microsoft/applicationinsights-shims@2.0.0  deduped

And it started causing the same issue as above

// compiled 
 var ReactPlugin =
  66491 | /** @class */
  66492 | function (_super) {
> 66493 |   __extends(ReactPlugin, _super);
        |   ^  66494 | 
  66495 |   function ReactPlugin() {
  66496 |     var _this = _super !== null && _super.apply(this, arguments) || this;


// source
  14 | import { IReactExtensionConfig } from './Interfaces/IReactExtensionConfig';
  15 | import { History, LocationListener, Location, Action } from "history";
  16 | 
> 17 | export default class ReactPlugin extends BaseTelemetryPlugin {
  18 |     public priority = 185;
  19 |     public identifier = 'ReactPlugin';
  20 | 

What our fix was to revert back to the following version
@microsoft/applicationinsights-react-js v3.1.0

| `-- @microsoft/applicationinsights-web@2.6.2
|   +-- @microsoft/applicationinsights-analytics-js@2.6.2
|   | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
|   +-- @microsoft/applicationinsights-channel-js@2.6.2
|   | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
|   +-- @microsoft/applicationinsights-dependencies-js@2.6.2
|   | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
|   +-- @microsoft/applicationinsights-properties-js@2.6.2
|   | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
|   `-- @microsoft/applicationinsights-shims@2.0.0
`-- @microsoft/applicationinsights-react-js@3.1.0
  +-- @microsoft/applicationinsights-common@2.6.2
  | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
  +-- @microsoft/applicationinsights-core-js@2.6.2
  | `-- @microsoft/applicationinsights-shims@2.0.0  deduped
  `-- @microsoft/applicationinsights-shims@1.0.3

@MSNev
Copy link
Collaborator

MSNev commented Apr 26, 2021

Oh well crap!

I forgot to update the packaging step to re-use the shims instance.
I'll create a new bug and publish another version.

@MSNev
Copy link
Collaborator

MSNev commented Apr 26, 2021

I've deprecated the react v3.1.1 and react-native v2.3.1 packages until I can publish an updated versions

@MSNev
Copy link
Collaborator

MSNev commented Apr 26, 2021

#1553

@MSNev
Copy link
Collaborator

MSNev commented Apr 28, 2021

I'm updating #1553 with the current state, please see comments there for additional info.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants