ember-decorators icon indicating copy to clipboard operation
ember-decorators copied to clipboard

Babel not auto-configured when used in an addon

Open buschtoens opened this issue 7 years ago • 15 comments

I just tried to use ember-decorators in an addon and was happy to see that https://github.com/rwjblue/ember-decorators/commit/93289926e8bfbe2b0f4aa4d4ccbc55b9cd80662e removed the setup section from the README, including the setup for usage in addons.

However, I still had to include the init patch in my addon's index.js. Was that piece of the README removed by accident or should this work without manually adding the plugins in index.js?

buschtoens avatar Jul 20 '17 12:07 buschtoens

It should work properly in addons also, can you whip up a demo repo so we can all try to poke at it.

rwjblue avatar Jul 20 '17 12:07 rwjblue

Yeppa :slightly_smiling_face:

https://github.com/buschtoens/ember-light-table-cell-type-multi-value/tree/ember-decorators-auto-config

Edit: I pushed an ember-decorators-auto-config branch for your convenience. :wink:

buschtoens avatar Jul 20 '17 13:07 buschtoens

ok, so it looks like the issue here is that Ember-CLI considers dependencies in an addon to actually be addon dependencies, and devDependencies to be the Dummy app's dependencies. By putting ember-decorators in devDeps, it included the addon for the Dummy app (with the dummy app as the parent) and so it only added the plugins to your Dummy app's transpiled code, not the actual addon code. Including it in dependencies applies it to both.

Not sure if this behavior is documented in Ember-CLI but we should definitely document it in our README.

pzuraq avatar Jul 21 '17 19:07 pzuraq

@pzuraq Very relevant https://github.com/tomdale/ember-cli-addon-tests/pull/106#issuecomment-315264011

kellyselden avatar Jul 21 '17 20:07 kellyselden

Oh gosh. What a rookie mistake. 🤦‍♂️ Thank you, guys!

Adding the -S option should fix it: ember install -S ember-decorators

I don't think that's a problem exclusive to ember-decorators, but I am happy to submit a PR adding a note to the installation instructions regarding add-ons.

buschtoens avatar Jul 22 '17 10:07 buschtoens

Yeah, that'd be awesome 👌

pzuraq avatar Jul 22 '17 20:07 pzuraq

I think I'm having a similar issue. I don't understand the proper way to install this dependency for an addon. Everything I try lands with:

Build Error (Babel)

ember-labs-maps/components/labs-layers-tooltip.js: Unexpected token (10:2)

   8 |
   9 | export default class LabsLayersTooltipComponent extends Component {
> 10 |   @computed('top', 'left', 'offset')
     |   ^

What are the correct steps for installing this in an addon?

allthesignals avatar May 17 '18 20:05 allthesignals

If you run ember install ember-decorators it should also install @ember-decorators/babel-transforms at the latest version. Can you confirm that the babel transforms addon has been added to your package.json?

pzuraq avatar May 17 '18 20:05 pzuraq

Thanks, @pzuraq - yes, this is a snippet of my package.json:

  "dependencies": {
    "ember-cli-babel": "^6.6.0",
    "ember-decorators": "2.0.0"
  },
  "devDependencies": {
    "@ember-decorators/babel-transforms": "^2.0.0",
    "babel-eslint": "8.2.3",
    //...

allthesignals avatar May 17 '18 20:05 allthesignals

ah, if this is an addon you'll have to include it in dependencies. We should definitely document this, and possibly update the blueprint to install it in the correct place.

pzuraq avatar May 17 '18 20:05 pzuraq

Happy to PR something, here's where I successfully landed:

  "dependencies": {
    "ember-cli-babel": "^6.6.0",
    "ember-decorators": "2.0.0",
    "@ember-decorators/babel-transforms": "^2.0.0",
    "babel-eslint": "8.2.3",
    "ember-cli-htmlbars": "^2.0.1",
    "ember-cli-htmlbars-inline-precompile": "^1.0.0"
  },
  "devDependencies": {
   //...

allthesignals avatar May 17 '18 20:05 allthesignals

I don't think babel-eslint should be necessary since apps that include your addon will not be linting your files (but they will be building them, hence needing the transforms)

pzuraq avatar May 17 '18 20:05 pzuraq

Same problem when developing a lazily-loaded in-repo ember engine. The solution seems to be to make sure @ember-decorators/babel-transforms and ember-decorators are in the dependencies block of the host.

luketheobscure avatar Jul 20 '18 18:07 luketheobscure

wow, I spent my whole afternoon chasing this down. I'm happy to update the documentation if someone wants to point me in the direction of how to do that. This really needs to be documented.

jalligator avatar Sep 24 '18 01:09 jalligator

@jalligator I think a "Usage in Addons" page would be great to add, and perfect for this.

pzuraq avatar Oct 01 '18 22:10 pzuraq