dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

Can't resolve 'graphql/language/visitor' when bundling using webpack for node target

Open SKoschnicke opened this issue 3 years ago • 1 comments

Expected behaviour I'm trying to add the dd-trace library to our Node.js express application, which is written in Typescript and build using Webpack. I followed these docs: https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/nodejs/?tab=otherenvironments#instrument-your-application I expect the application to build just fine using Webpack, as it was the case before adding the dd-trace library.

Actual behaviour I'm getting the following build errors:

yarn run v1.22.19
warning package.json: No license field
$ webpack
asset bundle.js 2.57 MiB [emitted] (name: main)
runtime modules 1.04 KiB 5 modules
cacheable modules 2.05 MiB 476 modules
+ 27 modules

WARNING in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/express/lib/application.js 22:11-28
 @ ./node_modules/express/lib/express.js 18:12-36
 @ ./node_modules/express/index.js 11:0-41
 @ ./index.ts 2:0-35 3:10-17

1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

ERROR in ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/transforms.js 9:18-53
Module not found: Error: Can't resolve 'graphql/language/visitor' in '/Users/sven/development/ct/datadog/node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools'
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/signature.js 6:21-44
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/index.js 6:18-40
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/index.js 219:25-43
 @ ./node_modules/dd-trace/packages/dd-trace/src/plugins/index.js 26:28-74
 @ ./node_modules/dd-trace/packages/dd-trace/src/plugin_manager.js 5:16-36
 @ ./node_modules/dd-trace/packages/dd-trace/src/proxy.js 10:22-49
 @ ./node_modules/dd-trace/packages/dd-trace/src/index.js 10:4-22
 @ ./node_modules/dd-trace/packages/dd-trace/index.js 4:22-38
 @ ./node_modules/dd-trace/index.js 3:0-47
 @ ./node_modules/dd-trace/init.js 3:15-27
 @ ./index.ts 1:0-23

ERROR in ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/transforms.js 10:18-53
Module not found: Error: Can't resolve 'graphql/language/printer' in '/Users/sven/development/ct/datadog/node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools'
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/signature.js 6:21-44
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/index.js 6:18-40
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/index.js 219:25-43
 @ ./node_modules/dd-trace/packages/dd-trace/src/plugins/index.js 26:28-74
 @ ./node_modules/dd-trace/packages/dd-trace/src/plugin_manager.js 5:16-36
 @ ./node_modules/dd-trace/packages/dd-trace/src/proxy.js 10:22-49
 @ ./node_modules/dd-trace/packages/dd-trace/src/index.js 10:4-22
 @ ./node_modules/dd-trace/packages/dd-trace/index.js 4:22-38
 @ ./node_modules/dd-trace/index.js 3:0-47
 @ ./node_modules/dd-trace/init.js 3:15-27
 @ ./index.ts 1:0-23

ERROR in ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/transforms.js 11:20-48
Module not found: Error: Can't resolve 'graphql/utilities' in '/Users/sven/development/ct/datadog/node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools'
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/signature.js 6:21-44
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/index.js 6:18-40
 @ ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/index.js 219:25-43
 @ ./node_modules/dd-trace/packages/dd-trace/src/plugins/index.js 26:28-74
 @ ./node_modules/dd-trace/packages/dd-trace/src/plugin_manager.js 5:16-36
 @ ./node_modules/dd-trace/packages/dd-trace/src/proxy.js 10:22-49
 @ ./node_modules/dd-trace/packages/dd-trace/src/index.js 10:4-22
 @ ./node_modules/dd-trace/packages/dd-trace/index.js 4:22-38
 @ ./node_modules/dd-trace/index.js 3:0-47
 @ ./node_modules/dd-trace/init.js 3:15-27
 @ ./index.ts 1:0-23

3 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.74.0 compiled with 3 errors and 1 warning in 1167 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

(there is by the way a bug in your issue template, as it says here under actual behaviour <!-- What should be happening. -->)

Steps to reproduce I created a demo project which also produces the above errors: https://github.com/SKoschnicke/datadog-test

Just clone it and do yarn install and then yarn build.

Environment

  • Operation system: macOS Monterey 12.6 M2 chip (also tested on Arch Linux x86)
  • Node.js version: 14.20.1
  • Relevant library versions: see https://github.com/SKoschnicke/datadog-test/blob/main/package.json

SKoschnicke avatar Sep 29 '22 12:09 SKoschnicke

This is because we use these modules but only when they are available. If you are not using GraphQL and these modules are not available, it's safe to compile without them since the GraphQL plugin will never be loaded in that case. You can find an example configuration for this in https://github.com/DataDog/dd-trace-js/issues/827#issuecomment-901218713

rochdev avatar Sep 30 '22 15:09 rochdev

Thank you @rochdev ! I was able to get it to build by adding this to the webpack config:

  externals: [
    'graphql/language/visitor',
    'graphql/language/printer',
    'graphql/utilities'
  ],

SKoschnicke avatar Oct 10 '22 10:10 SKoschnicke

This should be addressed in the library and not in every client. Same issues with Vite.

fallemand avatar Feb 27 '24 17:02 fallemand