nx icon indicating copy to clipboard operation
nx copied to clipboard

Running @storybook/angular:start-storybook with Storybook 8 fails to load preset

Open morgnism opened this issue 1 year ago • 4 comments
trafficstars

Current Behavior

Migrating an existing (working) angular app with storybook version 8 fails to launch in an angular monorepo.

Expected Behavior

The migrated storybook app should launch.

GitHub Repo

No response

Steps to Reproduce

Before migrating the project files, I generated a new storybook setup:

  1. Use Nx Console or cli to generate storybook for a shared lib: nx g @nx/angular:storybook-configuration shared-ui.
  2. Choose false on everything.
  3. Start the server with: npx nx run shared-ui:storybook
  4. See the failure log

Nx Report

Node   : 18.13.0
OS     : win32-x64
npm    : 8.19.3

nx                 : 19.2.3
@nx/js             : 19.2.3
@nx/jest           : 19.2.3
@nx/linter         : 19.2.3
@nx/eslint         : 19.2.3
@nx/workspace      : 19.2.3
@nx/angular        : 19.2.3
@nx/cypress        : 19.2.3
@nx/devkit         : 19.2.3
@nx/eslint-plugin  : 19.2.3
@nx/storybook      : 19.2.3
@nrwl/tao          : 19.2.3
@nx/web            : 19.2.3
@nx/webpack        : 19.2.3
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/cypress/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
@compodoc/compodoc : 1.1.25
@storybook/angular : 8.1.7

Failure Logs

SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: @storybook\angular\preset.

Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.

If you believe this is a bug, please open an issue on Github.

SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: .\node_modules\@storybook\angular\dist\server\framework-preset-angular-cli.js.

Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.

If you believe this is a bug, please open an issue on Github.

TypeError: (0 , os_1.availableParallelism) is not a function
    at Object.<anonymous> (.\node_modules\@angular\build\node_modules\piscina\dist\src\index.js:37:54)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Object.newLoader (.\node_modules\esbuild-register\dist\node.js:2262:9)
    at extensions..js (.\node_modules\esbuild-register\dist\node.js:4838:24)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at Module.require (.\node_modules\nx\src\adapter\compat.js:66:40)
    at require (node:internal/modules/cjs/helpers:103:18)
    at loadPreset (.\node_modules\@storybook\core-common\dist\index.js:12:59)
    at loadPreset (.\node_modules\@storybook\core-common\dist\index.js:12:59)
    at async Promise.all (index 0)
    at async loadPresets (.\node_modules\@storybook\core-common\dist\index.js:12:483)
    at async getPresets (.\node_modules\@storybook\core-common\dist\index.js:12:1503)
    at async buildDevStandalone (.\node_modules\@storybook\core-server\dist\index.js:77:2024)
    at async withTelemetry (.\node_modules\@storybook\core-server\dist\index.js:40:3599)

Package Manager Version

No response

Operating System

  • [ ] macOS
  • [ ] Linux
  • [X] Windows
  • [ ] Other (Please specify)

Additional Information

When running the generate script (nx Console or cli), here's a snapshot of the generated parts.

Note: there are references to tsconfig.storybook.json but this file is never generated.

project.json

"targets": {
     ...
    "storybook": {
      "executor": "@storybook/angular:start-storybook",
      "options": {
        "port": 4400,
        "configDir": "libs/shared/ui/.storybook",
        "browserTarget": "shared-ui:build-storybook",
        "compodoc": false
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    },
    "build-storybook": {
      "executor": "@storybook/angular:build-storybook",
      "outputs": ["{options.outputDir}"],
      "options": {
        "outputDir": "dist/storybook/shared-ui",
        "configDir": "libs/shared/ui/.storybook",
        "browserTarget": "shared-ui:build-storybook",
        "compodoc": false
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    }
}

nx.json:

{
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": [
       ...
      "!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)",
      "!{projectRoot}/.storybook/**/*",
      "!{projectRoot}/tsconfig.storybook.json"
    ],
    ...
  },
  "targetDefaults": {
    "build-storybook": {
      "cache": true,
      "inputs": [
        "default",
        "^production",
        "{projectRoot}/.storybook/**/*",
        "{projectRoot}/tsconfig.storybook.json"
      ]
    }
    ...
}

package.json (post upgrade to version 8. I don't know why it installs react??):

{
  "dependencies": {
     ...
      "react": "^18.2.0",
      "react-dom": "^18.2.0",
     ...
  },
  "defDependencies": {
      ...
      "@nx/storybook": "19.2.3",
      "@storybook/addon-a11y": "^8.0.10",
      "@storybook/addon-docs": "^8.0.10",
      "@storybook/addon-essentials": "8.1.7",
      "@storybook/addon-interactions": "^8.0.10",
      "@storybook/addon-links": "^8.0.10",
      "@storybook/angular": "8.1.7",
      "@storybook/blocks": "^8.0.10",
      "@storybook/core-server": "8.1.7",
      "@storybook/jest": "^0.2.3",
      "@storybook/test": "^8.0.10",
      "@storybook/testing-library": "^0.2.2",
      ...
}

morgnism avatar Jun 12 '24 18:06 morgnism

I gave this a fresh run again following the steps above and the server started up this time. The main change was updating my node version to LTS v22.3.0.

A few weird things about the generator still don't add up tho. i.e. Using the angular storybook configuration installs React, and references to files that haven't been generated.

morgnism avatar Jun 15 '24 04:06 morgnism

@morgnism Hello!

I'll dig deeper as soon as I can, however, the storybook app itself is built with React so it needs it as a dependency. I'll see if the react installation is coming from our side or the storybook side though

Coly010 avatar Jun 17 '24 08:06 Coly010

@morgnism Hello!

I'll dig deeper as soon as I can, however, the storybook app itself is built with React so it needs it as a dependency. I'll see if the react installation is coming from our side or the storybook side though

Thanks, Colum. Fyi, I upgraded to version 8 per the nx docs and noted the following:

  • Storybook's migration tool called out that react was installed and wasn't needed.
  • I experimented with a fresh project and install of storybook version 8, and it didn't ship with React. I didn't test in version 7 -- the version nx installs.

morgnism avatar Jun 17 '24 22:06 morgnism

We don't currently have official support for Storybook 8, but it is coming within the next two months. We may discover more as we add that support

Coly010 avatar Jun 26 '24 09:06 Coly010

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Sep 19 '24 00:09 github-actions[bot]