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

unable to resolve package {addon-name} when using HFTNB syntax to reference components in the same addon #1072

Closed
yangpiao opened this issue Jan 11, 2022 · 5 comments · Fixed by #1170

Comments

@yangpiao
Copy link

repo to reproduce: https://github.com/yangpiao/test-hftnb-embroider

Ran into this build error when I use HFTNB syntax in an addon to reference other components / helpers in the same addon.

E.g.

{{! test-hftnb-embroider/addon/components/foo-bar.hbs }}
<TestHftnbEmbroider$Lorem>
  {{yield}}
</TestHftnbEmbroider$Lorem>

I have set excludeNestedAddonTransforms to true, and the static***** options to true as well (ember-cli-build.js).

Build output:

$ ember b --environment test

Building into /private/var/folders/rj/swxy20tx7gx45_mmdxhdx80c000vbq/T/embroider/72ccc5
Environment: test
⠇ building... [@embroider/webpack]assets by chunk 640 KiB (id hint: vendors)
  asset chunk.952b5c45014cea2d5253.js 580 KiB [emitted] [immutable] [big] (id hint: vendors)
  asset chunk.a946c09be6f023797849.js 60.2 KiB [emitted] [immutable] (id hint: vendors)
asset chunk.36103af21939696d2b1e.js 34.9 KiB [emitted] [immutable] (name: assets/test.js)
asset chunk.a313cbe39e682ad36e3f.js 23 KiB [emitted] [immutable] (name: assets/dummy.js)
Entrypoint assets/dummy.js 83.2 KiB = chunk.a946c09be6f023797849.js 60.2 KiB chunk.a313cbe39e682ad36e3f.js 23 KiB
Entrypoint assets/test.js [big] 675 KiB = chunk.a946c09be6f023797849.js 60.2 KiB chunk.952b5c45014cea2d5253.js 580 KiB chunk.36103af21939696d2b1e.js 34.9 KiB
runtime modules 6.74 KiB 13 modules
modules by path ../../node_modules/ 258 KiB 78 modules
modules by path ./ 8.3 KiB 11 modules
modules by path ../../../ 243 KiB
  modules by path ../../../../../../../../../../Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/@babel/runtime/helpers/esm/*.js 1.63 KiB 4 modules
  ../../../../../../../../../../Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/qunit/qunit/qunit.js 242 KiB [built] [code generated]
  ../../../externals/require.js 108 bytes [built] [code generated]
modules by path ../../components/ 612 bytes
  modules by path ../../components/*.js 346 bytes 2 modules
  modules by path ../../components/*.hbs 266 bytes
    ../../components/foo-bar.hbs 1 bytes [built] [code generated] [1 error]
    ../../components/lorem.hbs 265 bytes [built] [code generated]

ERROR in ../../components/foo-bar.hbs
Module Error (from ../../../../../../../../../../Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/thread-loader/dist/cjs.js):
unable to resolve package test-hftnb-embroider from $TMPDIR/embroider/72ccc5
Thread Loader (Worker 1)
unable to resolve package test-hftnb-embroider from $TMPDIR/embroider/72ccc5

    at PackageCache.resolve (/Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/@embroider/shared-internals/src/package-cache.js:29:21)
    at CompatResolver.tryComponent (/Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/@embroider/compat/src/resolver.js:411:77)
    at CompatResolver.resolveElement (/Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/@embroider/compat/src/resolver.js:576:26)
    at enter (/Users/ypiao/ui/tests/test-hftnb-embroider/node_modules/@embroider/compat/src/resolver-transform.js:141:57)
    at visitNode ($TMPDIR/embroider/72ccc5/node_modules/ember-source/vendor/ember/ember-template-compiler.js:11763:16)
    at visitArray ($TMPDIR/embroider/72ccc5/node_modules/ember-source/vendor/ember/ember-template-compiler.js:11855:20)
    at visitKey ($TMPDIR/embroider/72ccc5/node_modules/ember-source/vendor/ember/ember-template-compiler.js:11831:7)
    at visitNode ($TMPDIR/embroider/72ccc5/node_modules/ember-source/vendor/ember/ember-template-compiler.js:11785:9)
    at traverse ($TMPDIR/embroider/72ccc5/node_modules/ember-source/vendor/ember/ember-template-compiler.js:11896:5)
    at preprocess ($TMPDIR/embroider/72ccc5/node_modules/ember-source/vendor/ember/ember-template-compiler.js:13445:9)
 @ ../../components/foo-bar.js 2:0-37 3:36-44
 @ ./tests/integration/components/foo-bar-test.js 1:0-54 3:9-11
 @ ./assets/test.js 4:9-67

webpack 5.65.0 compiled with 1 error in 7009 ms
@ef4
Copy link
Contributor

ef4 commented Jan 11, 2022

If somebody wants to debug and fix this I will merge PRs, but please understand that ember-holy-futuristic-template-namespacing-batman is very, very far down my list of priorities.

That addon tells you not to use it, it was deliberately named with a silly name so people wouldn't use it in production.

@rwjblue
Copy link
Collaborator

rwjblue commented Jan 11, 2022

After looking at the reproduction briefly, it seems that there is no way for this to ever resolve "itself":

resolve(packageName: string, fromPackage: Package): Package {
let cache = getOrCreate(this.resolutionCache, fromPackage, () => new Map() as Map<string, Package | null>);
let result = getOrCreate(cache, packageName, () => {
// the type cast is needed because resolvePackagePath itself is erroneously typed as `any`.
let packagePath = resolvePackagePath(packageName, this.basedir(fromPackage)) as string | null;
if (!packagePath) {
// this gets our null into the cache so we don't keep trying to resolve
// a thing that is not found
return null;
}
return this.get(dirname(packagePath));
});
if (!result) {
let e = new Error(`unable to resolve package ${packageName} from ${fromPackage.root}`);
(e as any).code = 'MODULE_NOT_FOUND';
throw e;
}
return result;
}

If you called cache.resolve('some-addon-name', packageForSomeAddonName), it will throw an error.

Changing that code above to something like this might work (though @ef4 would have to chime in RE: the validity):

    let result = getOrCreate(cache, packageName, () => {
      // the type cast is needed because resolvePackagePath itself is erroneously typed as `any`.
      let packagePath = resolvePackagePath(packageName, this.basedir(fromPackage)) as string | null;
      if (!packagePath) {
        if (fromPackage.isV2Addon() && fromPackage.name === packageName) {
          return fromPackage;
        } else {
          // this gets our null into the cache so we don't keep trying to resolve
          // a thing that is not found
          return null;
        }
      }
      return this.get(dirname(packagePath));
    });

@angelayanpan
Copy link
Collaborator

angelayanpan commented Jan 13, 2022

this seems to be impacting Service Injection as well?
Attempting to inject an unknown injection for @service('ember-cli-a11y-notifier@a11y-notifier') a11yNotifier;

@rwjblue
Copy link
Collaborator

rwjblue commented Mar 28, 2022

Should be resolved by #1170

@angelayanpan
Copy link
Collaborator

hi, it seems that the service usage of batman syntax is still not resolved with embroider 1.6 :(

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.

4 participants