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

Cannot read properties of undefined (reading 'registerV2Addon') #1325

Closed
gossi opened this issue Jan 11, 2023 · 1 comment · Fixed by #1327
Closed

Cannot read properties of undefined (reading 'registerV2Addon') #1325

gossi opened this issue Jan 11, 2023 · 1 comment · Fixed by #1327

Comments

@gossi
Copy link
Contributor

gossi commented Jan 11, 2023

I'm hunting a NPE for quite some time now - might be related to #1108

Cannot read properties of undefined (reading 'registerV2Addon')

I may have found a fix, but cannot be sure about this 100% yet - but enough to share here already.

The Situation

I'm upgrading hokulea to addons-v2. And with these addons v2 I see the error message above. Here is the monorepo and the dependency tree of relevant addons:

@hokulea/ember-actions-test-app
|- @hokulea/ember-actions
   |- ember-modifier
   `- @hokulea/ember-foundation
      `- ember-modifer

These are the noticable v2 addons, that will go through @embroider/addon-shim.

The Problem

Starting ember serve in @hokulea/ember-actions-test-app shows the error, that happens when an addon v2 depends on an addon v2 depends on an addon v2 - Two levels is the "threshold" here.

Reason for this in this line:

(this.parent as EAI2Instance).registerV2Addon(this.name, directory);

which calls this method:

registerV2Addon(name: string, root: string): void {
autoImportInstance!.registerV2Addon(name, root);
},

Now autoImportInstance is set in the code block linked above. Here is the trace in prose:

  1. this instance is only available to its direct children @hokulea/ember-actions (in the tree above).
  2. That is @hokulea/ember-actions has the chance to register its direct v2 addons (ember-modifer + @hokulea/ember-foundation).
  3. But at the addon instance of @hokulea/ember-foundation this autoImportInstance is undefined
  4. @hokulea/ember-foundation throws the error above

Given autoImportInstance is a local variable not "deeply" available, which makes sense and the reason for two levels being the threshold

  1. first level: instantiation
  2. second level: use
  3. third level+: undefined 💣

The Suggested Fix

The fix is mentioned in the comment:

// if we're being used by a v2 addon, it also has this shim and will
// forward our registration onward to ember-auto-import

but not applied, it is not thrown "higher and higher". The fix would target registerV2Addon() method:

    registerV2Addon(name: string, root: string): void {
      if (autoImportInstance) {
        autoImportInstance.registerV2Addon(name, root);
      } else if (this.parent && this.parent.registerV2Addon) {
        this.parent.registerV2Addon(name, root);
      }
    },

Why I'm saying this is only a suggested fix: I'm not sure, if this piece of code is in the intention of the comment or if that means a different implementation (given I have basically no real knowledge about embroider).

What I can say, this makes my build passes this step - I have errors later on, so I cannot be sure as well.

This is ready enough for me for now to share. If my suggested fix is enough, then cool. If not a hint would be nice, so the next time I'm working on this, I can continue digging into it.

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

Successfully merging a pull request may close this issue.

2 participants