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

Error: "EmberObject.create no longer supports.." on Ember-4.12 addon - ONLY during embroider-safe scenario #733

Open
Pixelik opened this issue Sep 14, 2023 · 1 comment · May be fixed by #735 or DazzlingFugu/ember-cp-validations#2

Comments

@Pixelik
Copy link

Pixelik commented Sep 14, 2023

Environment

  • Ember Version: ~4.12.0
  • Ember CLI Version: ~4.12.2
  • Ember CP Validations Version: ^5.0.0

Steps to Reproduce

I updated my Ember Addon (v1) from Ember 4.8 to Ember 4.12.

The addon is using ember-cp-validations v5.

This is what my package.json looks like:

  "dependencies": {
    ...,
    "ember-cp-validations": "^5.0.0",
    ...
  },
  "devDependencies": {
    ...,
    "@babel/core": "^7.22.1",
    "@babel/eslint-parser": "^7.21.8",
    "@babel/plugin-proposal-decorators": "^7.21.0",
    ...,
    "@ember-intl/cp-validations": "^5.0.0",
    ...,
    "@embroider/test-setup": "^3.0.0",
    ...,
    "ember-auto-import": "^2.6.3",
    ...,
    "ember-qunit": "^6.2.0",
    "ember-resolver": "^10.0.0",
    "ember-source": "~4.12.0",
    ...,
    "qunit": "^2.19.4",
    ...,
    "webpack": "^5.0.0
  },
  "peerDependencies": {
    "ember-source": "^4.8.0"
  },
  "resolutions": {
    "@embroider/macros": "^1.12.2"
  }

Everything works and all tests are passing, except when running the embroider-safe scenario where this error is thrown:

Error: Assertion Failed: EmberObject.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().
    at assert (http://localhost:4200/assets/test-support.js:233:15)
    at initialize (http://localhost:4200/assets/vendor.js:30952:81)
    at Class.create (http://localhost:4200/assets/vendor.js:31314:9)
    at new Options (webpack://dummy/../rewritten-packages/ember-cp-validations.126a452a/-private/options.js?:39:26)
    at Class.buildOptions (webpack://dummy/../rewritten-packages/ember-cp-validations.126a452a/validators/base.js?:130:12)
    at Class.init (webpack://dummy/../rewritten-packages/ember-cp-validations.126a452a/validators/base.js?:110:78)
    at Class.superWrapper [as init] (http://localhost:4200/assets/vendor.js:23897:22)
    at initialize (http://localhost:4200/assets/vendor.js:30988:9)
    at Class.create (http://localhost:4200/assets/vendor.js:31312:9)
    at InternalFactoryManager.create (http://localhost:4200/assets/vendor.js:13726:25)

I understand that the Error itself EmberObject.create no longer supports defining computed properties. is a known issue, but I'm only getting it during the embroider-safe test scenario.
In the default scenario everything is working fine and all tests are passing.

Any help would be much appreciated 🙏

@Pixelik Pixelik changed the title Throws EmberObject.create Error, on Ember-4.12 addon (v1), but only during embroider-safe scenario Throws Error, on Ember-4.12 addon (v1), but only during embroider-safe scenario Sep 14, 2023
@Pixelik Pixelik changed the title Throws Error, on Ember-4.12 addon (v1), but only during embroider-safe scenario Throws Error on Ember-4.12 addon during embroider-safe scenario Sep 14, 2023
@Pixelik Pixelik changed the title Throws Error on Ember-4.12 addon during embroider-safe scenario Error: "EmberObject.create no longer supports.." on Ember-4.12 addon - *only* during embroider-safe scenario Sep 14, 2023
@Pixelik Pixelik changed the title Error: "EmberObject.create no longer supports.." on Ember-4.12 addon - *only* during embroider-safe scenario Error: "EmberObject.create no longer supports.." on Ember-4.12 addon - ONLY during embroider-safe scenario Sep 14, 2023
@Pixelik
Copy link
Author

Pixelik commented Sep 14, 2023

👀 If I change ember-cp-validations/addon/-private/options.js from:

export default class Options {
  constructor({ model, attribute, options = {} }) {
    const optionKeys = keys(options);
    const createParams = { [OPTION_KEYS]: optionKeys, model, attribute };

    // If any of the options is a CP, we need to create a custom class for it
    if (optionKeys.some((key) => isDescriptor(options[key]))) {
      return OptionsObject.extend(options).create(createParams);
    }

    return OptionsObject.create(createParams, options);
  }
}

to:

export default class Options {
  constructor({ model, attribute, options = {} }) {
    const optionKeys = keys(options);
    const createParams = { [OPTION_KEYS]: optionKeys, model, attribute };
    const someOptionsAreCPs = optionKeys.some((key) => {
      return isDescriptor(options[key]) || options[key]?.constructor?.name === 'AliasDecoratorImpl'
    });
    
    // If any of the options is a CP, we need to create a custom class for it
    if (someOptionsAreCPs) {
      return OptionsObject.extend(options).create(createParams);
    }

    return OptionsObject.create(createParams, options);
  }
}

the error is gone and everything works.

Is this a valid fix ? Should I open a PR ?

Bear in mind that I'm only having the Error when running the embroider-safe scenario and not the default scenario on Ember 4.12.

🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment