From aca743b4996e8d3cfcc084bc503a49c468ce6668 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Mon, 28 Apr 2025 05:19:55 -0700 Subject: [PATCH] [docs] Upgrade note with Jest version requirements and workaround for older versions of Jest (#5619) Co-authored-by: Marc Pichler --- doc/frequently-asked-questions.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 doc/frequently-asked-questions.md diff --git a/doc/frequently-asked-questions.md b/doc/frequently-asked-questions.md new file mode 100644 index 000000000..d3f7167c4 --- /dev/null +++ b/doc/frequently-asked-questions.md @@ -0,0 +1,28 @@ +# Frequently Asked Questions + +This FAQ has bits of advice and workarounds for common problems. + +## I'm using Jest and get import errors when I run my test suite + +Test suite failures of the form: + +``` text +Cannot find module @opentelemetry/foo/bar from @opentelemetry/... +``` + +but package `@opentelemetry/foo` is installed may occur with Jest < v29.4. +This is because older versions of `jest-resolve` cannot find the nested module +imports used by some OpenTelemetry packages since version 0.56 and higher. +See [#5618](https://github.com/open-telemetry/opentelemetry-js/issues/5618) + +Either upgrade to a newer version of Jest to resolve the issue, or use this +workaround for older versions of Jest by adding a `moduleNameMapper` rule. +Add this line to your `jest.config.js`: + +``` javascript +module.exports = { + moduleNameMapper: { + '^@opentelemetry/([^/]+)/(.+)$': '/node_modules/@opentelemetry/$1/build/src/index-$2', + } +} +```