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

BasePlugin.js - Critical dependency warning in webpack #814

Closed
lukomwro opened this issue Feb 26, 2020 · 6 comments · Fixed by #981
Closed

BasePlugin.js - Critical dependency warning in webpack #814

lukomwro opened this issue Feb 26, 2020 · 6 comments · Fixed by #981
Labels
bug Something isn't working

Comments

@lukomwro
Copy link

lukomwro commented Feb 26, 2020

What version of OpenTelemetry are you using?

0.4.0

What version of Node are you using?

12.4.0

What did you do?

I've added telemetry script with some plugins UserInteractionPlugin and DocumentLoad. The code is copied from examples

import { DocumentLoad } from '@opentelemetry/plugin-document-load';
import { UserInteractionPlugin } from '@opentelemetry/plugin-user-interaction'
import { ZoneScopeManager } from '@opentelemetry/scope-zone'
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'
import { WebTracerProvider } from '@opentelemetry/web'

const providerWithZone = new WebTracerProvider({
  scopeManager: new ZoneScopeManager(),
  plugins: [new UserInteractionPlugin(), new DocumentLoad()],
})

providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()))

console.log('telemetry started')

What did you expect to see?

Complication without warnings

What did you see instead?

Compiled with warnings.

./node_modules/@opentelemetry/core/build/src/trace/instrumentation/BasePlugin.js
Critical dependency: the request of a dependency is an expression

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

Additional context

I'm using the latest create-react-app boilerplate with TypeScript template.

Webpack version 4.41.5

@lukomwro lukomwro added the bug Something isn't working label Feb 26, 2020
@dyladan
Copy link
Member

dyladan commented Feb 27, 2020

This happens because the Plugin system uses a dynamic require statement in order to load node plugins. It should not affect the behavior of web plugins, but you will still get the warning because webpack does not know that the dynamic require only runs in node. I will look into fixes for this.

@stephanos
Copy link

I just ran into the same issue. Is there a workaround? It seems like it's basically bricked when using webpack.

@dyladan
Copy link
Member

dyladan commented Mar 19, 2020

it should still work with warnings

@stephanos
Copy link

Hm, the build step of my React app completely fails.

I fixed it with this:

"postinstall": "file=./node_modules/@opentelemetry/core/build/src/trace/instrumentation/BasePlugin.js && awk '!/ = require/' $file > tmp && mv tmp $file",

(not proud of it)

@dyladan
Copy link
Member

dyladan commented Mar 19, 2020

Do plugins still load correctly after you've done that? The require isn't needed for web plugins so it should be ok. This will probably require changing to a platform specific base plugin to fix @mayurkale22 @obecny WDYT?

@stephanos
Copy link

stephanos commented Mar 19, 2020

Yes, I'm using the XMLHttpRequestPlugin and it works fine.

as for fixing this, maybe consider adding a big if statement at the top of that internal function that checks for a constant that Webpack knows and it then (hopefully) just ignores the code in there if it's not on Node?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants