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

fix: Correct build outputs #3211

Closed
wants to merge 2 commits into from
Closed

fix: Correct build outputs #3211

wants to merge 2 commits into from

Conversation

rschristian
Copy link
Contributor

@rschristian rschristian commented Feb 25, 2023

Closes #3208

@codesandbox
Copy link

codesandbox bot commented Feb 25, 2023

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 25, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bfea34d:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

@markerikson markerikson added this to the 2.0 milestone Feb 25, 2023
@rschristian
Copy link
Contributor Author

rschristian commented Mar 18, 2023

Came back to fix up any remaining test issues (sorry for the long delay), but looks like it was just an issue with my Node version. Didn't realize the project targets v16+, so nullish coalescing syntax errors aren't actually an issue.

I'll mark this as ready for review, but feel free to copy/paste or fold into anything else, obviously this change is quite tiny and is just implementing what we talked about in the linked issue.

Edit: Hm, looks like something is going wrong when testing against dist/

Edit2: Best guess is yarn is doing something weird when resolving modules, but I'm really unfamiliar with v2+. I'll reopen this but there might still be an issue with the CI and/or testing setup.

@rschristian rschristian marked this pull request as ready for review March 18, 2023 07:47
@rschristian rschristian marked this pull request as draft March 18, 2023 07:56
@rschristian rschristian marked this pull request as ready for review March 18, 2023 08:31
@markerikson
Copy link
Collaborator

The build errors all say it can't find the @reduxjs/toolkit entry point. So, most likely something about this change is breaking the package definition :(

@rschristian
Copy link
Contributor Author

rschristian commented Mar 19, 2023

The build errors all say it can't find the @reduxjs/toolkit entry point. So, most likely something about this change is breaking the package definition :(

Oh god dammit, it's the "files" array in the package.json -- .mjs entries aren't white listed 😅.

I was testing with yalc but was confident enough in my eye-balling (and this issue being CJS-specific) that I didn't switch to test those entries.

Gonna start making notches in my desk for every time that's screwed me up, been quite a few times over the years.

Note: redux-thunk will still cause issues, its alpha has the same problem that this fixes. I think that's the remaining issue, but these errors from Vitest (?) are far less clear than Node's

@markerikson
Copy link
Collaborator

OOOOO-kay!

After a very long day today (and a bunch more hours on previous weekends), I have finally come up with a set of packaging changes that appears to be as "correct" as I think we're gonna get, and I've got it being verified via a battery of CI tests that build and run a set of example apps using the PR build artifact. There's also a CI test that uses are-the-types-wrong to verify that the entry points actually seem to work as expected.

I've published new alphas of redux and redux-thunk using the package config you have here as a starting point.

Here's what I ended up with for redux:

  "main": "dist/cjs/redux.cjs",
  "module": "dist/redux.legacy-esm.js",
  "types": "dist/redux.d.ts",
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "types": "./dist/redux.d.ts",
      "import": "./dist/redux.mjs",
      "default": "./dist/cjs/redux.cjs"
    }
  },

Note the use of module with a .js extension for Webpack 4 compat. I found that one out the hard way - the cra4 test example failed to find imports when RTK and Redux had a .mjs file in the module key :(

Similarly, for RTK:

  "module": "dist/redux-toolkit.legacy-esm.js",
  "main": "dist/cjs/index.js",
  "types": "dist/index.d.ts",
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/redux-toolkit.modern.mjs",
      "default": "./dist/cjs/index.js"
    },
    "./query": {
      "types": "./dist/query/index.d.ts",
      "import": "./dist/query/rtk-query.modern.mjs",
      "default": "./dist/query/cjs/index.js"
    },
    "./query/react": {
      "types": "./dist/query/react/index.d.ts",
      "import": "./dist/query/react/rtk-query-react.modern.mjs",
      "default": "./dist/query/react/cjs/index.js"
    }
  },

And then I'm still having to use the fallback query/package.json-type files for Webpack 4 as well.

Those changes are over in #3318 , which I'm about to merge.

Thank you for helping sort out what the apparently-right keys are and pointing me in the right direction!

@markerikson markerikson closed this Apr 3, 2023
@rschristian rschristian deleted the fix/pkg-exports branch April 3, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants