ember-cli / ember-template-imports

Template import support in Ember!
MIT License
74 stars 39 forks source link

Import does not work if it is used only in a template #239

Closed BwehaaFox closed 4 months ago

BwehaaFox commented 4 months ago

I decided to start adapting my project to a new type of template, I did everything according to instructions. The new format began to be assembled successfully. With one thing:

import { or } from 'ember-truth-helpers';
import Component from '@glimmer/component';

export default class extends Component<Args> {
  <template>
    {{#if (or 1 2)}}

    {{/if}}
  </template>
}

Ember gives an error that or was not found, but if you simply write or anywhere except template, the template starts working correctly

...
or 
export default class extends Component<Args> {
  <template>
    {{#if (or 1 2)}}
   ...
"ember-cli": "^5.5.0",
"ember-template-imports": "^4.1.1",
"webpack": "^5.89.0"

The situation is confusing me, and I can’t figure out where to start solving the problem.

NullVoxPopuli commented 4 months ago

is:

and then in your lockfile:

?

BwehaaFox commented 4 months ago

ember-auto-import was version 2.7.2. upgraded to v2.7.3. The rest of the packages were informed decisions

Now there are 2 definitions in the lock file

babel-plugin-ember-template-compilation@^2.0.0, babel-plugin-ember-template-compilation@^2.0.1:
  version "2.2.0"
  resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-2.2.0.tgz#b119fadcd5c831299fbd706420d2ea742848a659"
  integrity sha512-1I7f5gf06h5wKdKUvaYEIaoSFur5RLUvTMQG4ak0c5Y11DWUxcoX9hrun1xe9fqfY2dtGFK+ZUM6sn6z8sqK/w==
  dependencies:
    "@glimmer/syntax" "^0.84.3"
    babel-import-util "^2.0.0"

babel-plugin-ember-template-compilation@^2.2.5:
  version "2.2.5"
  resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-2.2.5.tgz#9f00cc88eeefdc7d228cfac63c2a40e59691fbf3"
  integrity sha512-NQ2DT0DsYyHVrEpFQIy2U8S91JaKSE8NOSZzMd7KZFJVgA6KodJq3Uj852HcH9LsSfvwppnM+dRo1G8bzTnnFw==
  dependencies:
    "@glimmer/syntax" "^0.84.3"
    babel-import-util "^3.0.0"

But the problem was not solved. Now there are such definitions of the dependencies of the packages indicated above

ember-auto-import@^2.0.0, ember-auto-import@^2.3.0, ember-auto-import@^2.4.0, ember-auto-import@^2.4.2, ember-auto-import@^2.4.3, ember-auto-import@^2.5.0, ember-auto-import@^2.6.0, ember-auto-import@^2.6.3:
  version "2.6.3"
  resolved "https://registry.yarnpkg.com/ember-auto-import/-/ember-auto-import-2.6.3.tgz#f18d1b93dd10b08ba5496518436f9d56dd4e000a"
  integrity sha512-uLhrRDJYWCRvQ4JQ1e64XlSrqAKSd6PXaJ9ZsZI6Tlms9T4DtQFxNXasqji2ZRJBVrxEoLCRYX3RTldsQ0vNGQ==
  dependencies:
    "@babel/core" "^7.16.7"
    "@babel/plugin-proposal-class-properties" "^7.16.7"
    "@babel/plugin-proposal-decorators" "^7.16.7"
    "@babel/preset-env" "^7.16.7"
    "@embroider/macros" "^1.0.0"
    "@embroider/shared-internals" "^2.0.0"
    babel-loader "^8.0.6"
    babel-plugin-ember-modules-api-polyfill "^3.5.0"
    babel-plugin-ember-template-compilation "^2.0.1"
   ...

ember-auto-import@^2.7.3:
  version "2.7.3"
  resolved "https://registry.yarnpkg.com/ember-auto-import/-/ember-auto-import-2.7.3.tgz#08421f35cd9628327e1dd5d9df40673a1d7beb71"
  integrity sha512-EQzStGYxNvTPYWCFh0X57HFAzAvA2rHHRgBeWNDKHQ/rENNlHw0c0e0i1XebwEfv+yGHOodE4dN+f/mrYkQXLw==
  dependencies:
    "@babel/core" "^7.16.7"
    "@babel/plugin-proposal-class-properties" "^7.16.7"
    "@babel/plugin-proposal-decorators" "^7.16.7"
    "@babel/plugin-proposal-private-methods" "^7.16.7"
    "@babel/plugin-transform-class-static-block" "^7.16.7"
    "@babel/preset-env" "^7.16.7"
    "@embroider/macros" "^1.0.0"
    "@embroider/shared-internals" "^2.0.0"
    babel-loader "^8.0.6"
    babel-plugin-ember-modules-api-polyfill "^3.5.0"
    babel-plugin-ember-template-compilation "^2.0.1"
    ...

ember-cli-htmlbars@^4.2.0, ember-cli-htmlbars@^5.3.1, ember-cli-htmlbars@^5.7.1, ember-cli-htmlbars@^6.0.0, ember-cli-htmlbars@^6.0.1, ember-cli-htmlbars@^6.1.0, ember-cli-htmlbars@^6.1.1, ember-cli-htmlbars@^6.2.0, ember-cli-htmlbars@^6.3.0:
  version "6.3.0"
  resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-6.3.0.tgz#ac85f2bbd09788992ab7f9ca832cd044fb8e5798"
  integrity sha512-N9Y80oZfcfWLsqickMfRd9YByVcTGyhYRnYQ2XVPVrp6jyUyOeRWmEAPh7ERSXpp8Ws4hr/JB9QVQrn/yZa+Ag==
  dependencies:
    "@ember/edition-utils" "^1.2.0"
    babel-plugin-ember-template-compilation "^2.0.0"
    babel-plugin-htmlbars-inline-precompile "^5.3.0"
   ...
BwehaaFox commented 4 months ago

Installing these resolutions solved the problem, now everything works even if I remove the resolutions and run yarn install

"resolutions": {
   "ember-auto-import": "2.7.3",
   "ember-auto-import/babel-plugin-ember-template-compilation": "^2.2.5"
}

lock file is fixed in this form

ember-auto-import@^2.0.0, ember-auto-import@^2.3.0, ember-auto-import@^2.4.0, ember-auto-import@^2.4.2, ember-auto-import@^2.4.3, ember-auto-import@^2.5.0, ember-auto-import@^2.6.0, ember-auto-import@^2.6.3, ember-auto-import@^2.7.3:
  version "2.7.3"
  resolved "https://registry.yarnpkg.com/ember-auto-import/-/ember-auto-import-2.7.3.tgz#08421f35cd9628327e1dd5d9df40673a1d7beb71"
  integrity sha512-EQzStGYxNvTPYWCFh0X57HFAzAvA2rHHRgBeWNDKHQ/rENNlHw0c0e0i1XebwEfv+yGHOodE4dN+f/mrYkQXLw==
  dependencies:
    "@babel/core" "^7.16.7"
    "@babel/plugin-proposal-class-properties" "^7.16.7"
    "@babel/plugin-proposal-decorators" "^7.16.7"
    "@babel/plugin-proposal-private-methods" "^7.16.7"
    "@babel/plugin-transform-class-static-block" "^7.16.7"
    "@babel/preset-env" "^7.16.7"
    "@embroider/macros" "^1.0.0"
    "@embroider/shared-internals" "^2.0.0"
    babel-loader "^8.0.6"
    babel-plugin-ember-modules-api-polyfill "^3.5.0"
    babel-plugin-ember-template-compilation "^2.0.1"
    babel-plugin-htmlbars-inline-precompile "^5.2.1"

Is this the correct solution to the problem?

NullVoxPopuli commented 4 months ago

If you're using yarn@v1, that's probably all you can do short of deleting the lockfile.

There may be a command to update your indirect dependencies?

BwehaaFox commented 4 months ago

Thanks for the tips, it saved me several desperate days