storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
83.43k stars 9.12k forks source link

Storybook broken in Ember 4.X #18028

Open bakerac4 opened 2 years ago

bakerac4 commented 2 years ago

Describe the bug Storybook is completely broken when trying to use it in Ember 4.X Ember 4 removes deprecated features, one of those being Global Ember usage. See https://github.com/storybookjs/ember-cli-storybook/issues/103 for more information

After doing a bit of research there are a few target areas that will need to be fixed.

  1. You'll need to use babel-plugin-ember-template-compilation here
var extraPlugins = [[require.resolve('babel-plugin-ember-template-compilation'), {
      precompile: precompileWithPlugins,
      outputModuleOverrides: {
            '@ember/template-factory': {
              createTemplateFactory: ['createTemplateFactory', '@glimmer/core'],
            }
          },
    enableLegacyModules: ['ember-cli-htmlbars', 'ember-cli-htmlbars-inline-precompile', 'htmlbars-inline-precompile']
  }]];
  1. You'll need to update https://github.com/storybookjs/storybook/blob/4b47793e118f091971f2a453d486c5f01875811d/app/ember/src/client/preview/render.ts#L41 to remove the global ember usage. There is a pull request for this already, but Im not quite sure if you will also have to update it to be a glimmer component and use setComponentTemplate.

  2. You might need https://github.com/glimmerjs/glimmer-vm/issues/1252 to be fixed - because you'll run into that once you make the first change.

Even with all this, I still wasn't able to get it 100% working - but I was able to bypass the Ember is not defined error.

dbendaou commented 2 years ago

For the 2nd one there's a MR open already https://github.com/storybookjs/storybook/pull/17843

We could switch to glimmer but that should be enough for fixing the Ember is not defined wdyt?

bakerac4 commented 2 years ago

Im by no means an expert in the internals of ember, or storybook at all (I really just wanted to try storybook for the first time haha) but it seems like you would need to attack it from multiple sides due to how storybook renders.

It seems to take your template on client side and convert it via template compiler. Then it uses that compiled template on the server side. And both "sides" actually have an issue with using the global Ember variable.

RobbieTheWagner commented 1 year ago

Any updates here? I'm having a lot of Ember 4 / addon v2 issues.

dbendaou commented 1 year ago

Can you copy past which errors you have? I have an ember addon working with Ember 4 & embroider safe The only issue that I got was related to doc.json not working (API of component through YUIdoc)

pomm0 commented 1 year ago

I'm also not able to update my addon to Ember version 4. But I stuck at the very first step: installing node modules because storybooks' package.json only allows ember 3.x:

"ember-source": "^3.16.0"
olyckne commented 1 year ago

@pomm0 I've solved that by putting an override in package.json.

"overrides": {
    "@storybook/ember": {
      "ember-source": "~4.8.0"
    },
}
jayjayjpg commented 1 year ago

In an Ember 4 addon that I'm trying to upgrade with the respective new version of storybook@6.5.15, I can see that the missing Ember global error has disappeared, but I'm running into additional build issues when running npm run storybook:

99% done plugins webpack-hot-middlewarewebpack built preview dce4affe3ddb6eed9fb4 in 8894ms
ModuleNotFoundError: Module not found: Error: Can't resolve '@ember/component' in '/my/path/ember4-storybook-example-addon/node_modules/@storybook/ember/dist/esm/client/preview'

// ...

  Parsed request is a module
  using description file: /my/path/ember4-storybook-example-addon/node_modules/@storybook/ember/package.json (relative path: ./dist/esm/client/preview)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module

I also created a reproduction repository here in case it is helpful as a reference: https://github.com/jayjayjpg/ember4-storybook-example-addon

Is there a way to contribute to a fix in @storybook/ember for this issue?

robclancy commented 1 year ago

This @ember/component issue seems to be one that is being ignored. I downgraded because of it and then run into the issue with the Ember global.