storybook: dist/cjs/server/options ERR_PACKAGE_PATH_NOT_EXPORTED in exports

Same for me as for @clover-omelnyk @shilman Can you please take a look?

I’m trying to use it with: "next": "12.2.2", "preact": "10.7.3", "preact-render-to-string": "5.2.0", "react": "npm:@preact/compat@^17.1.1", "react-dom": "npm:@preact/compat@^17.1.1"

info  @nrwl/storybook              ^14.5.7  →   ^14.6.0-beta.4
info  @storybook/addon-essentials   ~6.5.9  →  ~7.0.0-alpha.23
info  @storybook/builder-webpack5   ~6.5.9  →  ~7.0.0-alpha.23
info  @storybook/core-server        ~6.5.9  →  ~7.0.0-alpha.23
info  @storybook/manager-webpack5   ~6.5.9  →  ~7.0.0-alpha.10
info  @storybook/react              ~6.5.9  →  ~7.0.0-alpha.23

image

P.s. 6.5.9 is throwing an error about:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/klypalskyi/Documents/Techery/SunRider/sunrider/node_modules/react/package.json

_Originally posted by @Klypalskyi in https://github.com/storybookjs/storybook/issues/13099#issuecomment-1220018684_

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 14
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Hellooooooo everyone!!!

I am very sad to report that the Nx executors do NOT work with Storybook 7 yet. That, however, does NOT mean that you cannot use Nx with Storybook 7!

What you can do is the following:

  1. npx storybook@next upgrade --prerelease to install Storybook v7, or just update manually
  2. Do any manual changes to your files that are needed - see the Migration Guide. Make note to add the framework in all your .storybook/main.js files - manually for now 😦
  3. Go to your project’s directory (eg. apps/my-app or libs/my-lib) and run npx storybook dev or npx storybook build

Following these steps, it should work.

Now, if you want to run the task via Nx, you can create a new storybook target for your project using run-commands:

  1. Delete or rename your project’s storybook and build-storybook targets

  2. Run:

nx generate @nrwl/workspace:run-commands storybook --command='npx storybook dev' --project=<MY-PROJECT> --cwd=<PATH-TO-PROJECT-ROOT>

So if your project is a library called my-lib the command would be:

nx generate @nrwl/workspace:run-commands storybook --command='npx storybook dev' --project=my-lib --cwd=libs/my-lib
  1. That will add this new target to your libs/my-lib/project.json:
    "storybook": {
      "executor": "nx:run-commands",
      "outputs": [],
      "options": {
        "command": "npx storybook dev",
        "cwd": "libs/aaa"
      }
    }

And you can call this like:

nx run my-lib:storybook

NOTE: Please note that this is a temporary solution. And it might as well NOT WORK at all, at this stage. The Storybook v7 support for Nx is on the way. It’s not there yet. This is a temporary solution if you want to see it working.

Please please let me know if you have any questions.

@ndelangen @ild0tt0re the thing is that if you’re using Storybook 7, in my reproduction issue, I am just calling directly npx storybook build, so I’m not using @nrwl/storybook at all!!! I am just calling directly the storybook build, you see.

So I’m not using the Nx executors you link above at all for Storybook 7.

Ohhhh I see the confusion. The error reported initially in this issue is a different error than the one I am having. The error posted in the issue is indeed due to these imports that @ild0tt0re is talking about. The two implementations of Nx need to be refactored, to use the new standalone build. I have not done that yet, and that’s the reason one cannot use the Nx executors with Storybook v7.

Now, the issue I am having is something totally different. 😃

Do you a have a reproduction repo you can share? If not, can you create one? See how to create a repro. Thank you! 🙏

@shilman same issue with storybook 7.0.0-beta.19 in a Nx 15.4.2 monorepo.

REPRO

ERROR

NX Package subpath ‘./dist/cjs/server/options’ is not defined by “exports” in /path-to-my-project/dev/nx15/node_modules/@storybook/react/package.json

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/cjs/server/options' is not defined by "exports" in /path-to-my-project/node_modules/@storybook/react/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /path-to-my-project/dev/nx15/node_modules/.pnpm/@nrwl+storybook@15.4.3-beta.1_bdez2lbzd4g75f6q5wyqmfcjdy/node_modules/@nrwl/storybook/src/executors/storybook/storybook.impl.js:10:86

+1, have the same issue (7.0.0-beta.0)