@backstage/plugin-cost-insights 0.11.13 fails to load correctly in tests
See original GitHub issueExpected Behavior
Upgrading @backstage/plugin-cost-insights
should not cause any issues.
Current Behavior
Upgrading @backstage/plugin-cost-insights
from 0.11.12
to 0.11.13
causes test suite failure, with the error:
TypeError: Cannot read property 'default' of undefined
1 | import * as luxon from 'luxon';
> 2 | import { Duration } from '@backstage/plugin-cost-insights';
| ^
3 | import { DEFAULT_COST_DATE_FORMAT } from './format';
4 | import { assertNever } from './assert';
5 |
at ../../../node_modules/node_modules/react-dom/cjs/react-dom.development.js:18:13
at Object.<anonymous> (../../../node_modules/node_modules/react-dom/cjs/react-dom.development.js:25011:4)
at Object.<anonymous> (../../../node_modules/@backstage/plugin-cost-insights/dist/index.esm.js:1:348)
at Object.<anonymous> (utils/duration.ts:2:27)
at Object.<anonymous> (clients/costInsights/dummyUtils.ts:23:17)
at Object.<anonymous> (clients/costInsights/costInsightsClient.ts:14:19)
at Object.<anonymous> (clients/costInsights/costInsightsClient.test.ts:3:27)
While the tests fail, the build itself succeeds, and the application can run without any errors.
Possible Solution
It looks like in commit https://github.com/backstage/backstage/commit/be32bc3edbe758dd864f829142023904ba65944a, react-dom
was removed from the dependencies
in plugins/cost-insights/package.json
.
Looking at the dependency tree, there are multiple sub-dependencies of this plugin that require react-dom
as a peer. I am by no means an expert on peer dependencies, but it is my understanding that not re-declaring transitive peer dependencies can sometimes cause issues.
My best guess is that there are some resolution issues happening when using ts-node
(via the backstage-cli), since the issue only occurs during testing, and not while the application is actually running (when ts-node
is no longer in the picture).
One other thing I noticed, though I don’t think it is the cause of this issue, is that some of the downstream dependencies for the @backstage/plugin-cost-insights
plugin have peerDependencies requirements for React v15/v16, meaning that if v17 were to actually be used, it would potentially have errors, as it does not match downstream peer dependencies.
Steps to Reproduce
- Update
@backstage/plugin-cost-insights
from0.11.12
to0.11.13
- Run test on files that import anything from the plugin (3 separate test files are failing, all with the same error, importing different parts of the plugin).
Context
- Originally trying to do a version bump with
backstage-cli versions:bump
. Narrowed the problem down to just the one plugin. - When the plugin is updated, no other entry in the
yarn.lock
is changed, as the new plugin dependencies are already present from other plugins. react-dom
is installed in the app, andyarn why
shows only one version is installed (react-dom@16.14.0
).
Your Environment
- NodeJS Version (v14):
v14.17.6
- Operating System and Version (e.g. Ubuntu 14.04):
Linux 5.4.0-1063-azure - linux/x64
- Browser Information: N/A
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (11 by maintainers)
TL;DR: all of
@backstage/test-utils
was being built into the published package. Bit more details in the fix: #8644I’m afraid it’s a bit too late to unpublish at this point, but I added deprecation messages for the two broken releases