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

dependencySatisfies fails due to empty package.json #1332

Closed
simonihmig opened this issue Jan 20, 2023 · 2 comments
Closed

dependencySatisfies fails due to empty package.json #1332

simonihmig opened this issue Jan 20, 2023 · 2 comments

Comments

@simonihmig
Copy link
Collaborator

I have a v2 addon, that uses ensure-safe-component from @embroider/util (which is still v1, we should change that I think?). While it used to work for a while, at some point it started to fail Embroider tests with this runtime error:

Uncaught TypeError: Cannot read properties of undefined (reading '__loader') at webpack://test-app/../node_modules/.pnpm/@embroider+util@1.9.0_ember-source@4.10.0/node_modules/@embroider/util/ember-private-api.js

This happened in this PR of an OSS project. It uses pnpm, and as said it used to work, and the only change from a passing CI job to a failing was the change of some dependencies related to ESLint (see https://github.com/CrowdStrike/ember-headless-form/pull/14/commits, commit c094820 passing while cb2b675 is failing), so nothing that could have a direct effect, other than maybe pnpm reshuffling things somehow.

The cause of the error shown above is dependencySatisfies not getting the version of ember-source here (the only version of ember-source in node_modules is 4.10.0!). While debugging the @embroider/macros babel transform you could see this:

Bildschirm­foto 2023-01-20 um 10 54 02

As you can see, the .root of Package representing ember-source is somewhere in the temp build folder, and its package.json only contains a name property, no version, which obviously makes it return undefined for the version check of dependencySatisfies.

@NullVoxPopuli pointed out that this type of almost empty package.json is likely generated by the EmptyPackageTree broccoli plugin, utilized here. And indeed putting a breakpoint there shows ember-source being treated that way:

image

Probably this could be "fixed" by migrating embroider/util to v2? But it still reveals an issue with a different root cause here, doesn't it? Maybe it occurred for the first time that a v2 addon depends on a v1 addon (util), that needs to have access to package versions via dependencySatisfies? Still puzzling, how this has stopped working with some seemingly unrelated change (pnpm install)

@simonihmig
Copy link
Collaborator Author

Holy cow, after reading my own issue description, and double-checking that indeed the only change between passing and failing Embroider tests were unrelated dependency changes, I realized that that's not entirely true: I did add ember-source to the addon's devDependencies (probably for anticipating the changes in embroider-build/addon-blueprint#101)!

Now, after removing that again, and rm -rf $TMPDIR/embroider, things pass! 🤯

Still an underlying issue seems to exist...

@simonihmig
Copy link
Collaborator Author

Seems this was another case of pnpm behaving wierdly in a monorepo when not using dependenciesMeta.*.injected, resolving ember-source to a different version than what is used in the app. 😩

Closing in favour of #1349 and embroider-build/addon-blueprint#107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant