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

Core: Add CJS entrypoints to errors in core events #24038

Merged
merged 2 commits into from Sep 4, 2023

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Sep 1, 2023

Closes #24009

What I did

When running tests with composeStories in Jest where node with ESM is not enabled, the tests fail with:
image

This PR solves that.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Use this repro:

- const { Default } = composeStories(stories)
+ const { Primary } = composeStories(stories)
  • Update to the canary 0.0.0-pr-24038-sha-abd016e1
  • npm run test – it should work

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-24038-sha-abd016e1. Install it by pinning all your Storybook dependencies to that version.

More information
Published version 0.0.0-pr-24038-sha-abd016e1
Triggered by @yannbf
Repository storybookjs/storybook
Branch yann/fix-cjs-entries-on-core-events
Commit abd016e1
Datetime Sun Sep 3 19:48:50 UTC 2023 (1693770530)
Workflow run 6066425997

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=24038

@IanVS
Copy link
Member

IanVS commented Sep 2, 2023

Are you sure this is a cjs issue? I notice that the error message includes ".js" on the end of the file, which we don't include in our export map. Or, does jest just not respect / understand export maps.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yannbf yannbf force-pushed the yann/fix-cjs-entries-on-core-events branch from e7e3132 to abd016e Compare September 3, 2023 19:43
@yannbf
Copy link
Member Author

yannbf commented Sep 3, 2023

Are you sure this is a cjs issue? I notice that the error message includes ".js" on the end of the file, which we don't include in our export map. Or, does jest just not respect / understand export maps.

Any idea why this isn't handled by the export map? E.g.

I thought maybe the exports maps were an ESM only thing, but it might as well be an issue with Jest. I'm not entirely sure!

@yannbf yannbf added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Sep 3, 2023
@shilman shilman merged commit 509dc79 into next Sep 4, 2023
60 of 61 checks passed
@shilman shilman deleted the yann/fix-cjs-entries-on-core-events branch September 4, 2023 00:40
@github-actions github-actions bot mentioned this pull request Sep 4, 2023
5 tasks
storybook-bot pushed a commit that referenced this pull request Sep 4, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
@github-actions github-actions bot mentioned this pull request Sep 4, 2023
10 tasks
@IanVS
Copy link
Member

IanVS commented Sep 4, 2023

@SimenB, sorry for the ping, but I was wondering if Jest does not support export maps in package.json. This PR feels a little like a hack, and I was wondering if you knew of any better ways to add support for Jest in this case.

@IanVS
Copy link
Member

IanVS commented Sep 4, 2023

@yannbf do you know where the ".js" on the file name came from? Is that something in our code, or did it get added somewhere (maybe by jest itself)?

@yannbf
Copy link
Member Author

yannbf commented Sep 4, 2023

@yannbf do you know where the ".js" on the file name came from? Is that something in our code, or did it get added somewhere (maybe by jest itself)?

Alright I did a proper investigation and here's what's going on.
I believe most, if not all of the projects from #24009 use Jest 27, either from outdated dependencies or because of react-scripts. The issue happens in jest-resolve at this line: https://github.com/jestjs/jest/blob/main/packages/jest-resolve/src/resolver.ts#L351

This issue does not happen in Jest 29. jest-resolve v29 is able to resolve a package correctly based on its exports map.

Therefore, this PR is a workaround to maintain compatibility with jest 27 projects, and because we support CRA, it's important.

cc @shilman

@SimenB
Copy link
Contributor

SimenB commented Sep 4, 2023

Yeah, Jest has full support from v29 (partial support (. only) in v28)

storybook-bot pushed a commit that referenced this pull request Sep 6, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
storybook-bot pushed a commit that referenced this pull request Sep 6, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
storybook-bot pushed a commit that referenced this pull request Sep 7, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
storybook-bot pushed a commit that referenced this pull request Sep 8, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
storybook-bot pushed a commit that referenced this pull request Sep 8, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
storybook-bot pushed a commit that referenced this pull request Sep 8, 2023
…re-events

Core: Add CJS entrypoints to errors in core events
(cherry picked from commit 509dc79)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:normal core patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Bad import { composeStories } from '@storybook/react' in v7.4.0
4 participants