okikio / bundlejs

An online tool to quickly bundle & minify your projects, while viewing the compressed gzip/brotli bundle size, all running locally on your browser.
https://bundlejs.com
MIT License
751 stars 13 forks source link

Generates an incorrect URL for a Redux Toolkit nested entry point #58

Closed markerikson closed 2 months ago

markerikson commented 1 year ago

I'm trying to bundle this set of exports:

export { configureStore } from "@reduxjs/toolkit";
export {createApi} from "@reduxjs/toolkit/query/react";
export { Provider } from "react-redux";

It downloads React-Redux okay, but fails to download the RTK /query/react entry point, because it's generating a wrong version URL (1.0.0, when the current version is 1.9.5):

✘ [ERROR] Do not know how to load path: http-url:https://unpkg.com/@reduxjs/toolkit@1.0.0/dist/query/react/rtk-query-react.esm.js

/input.ts:2:24:

      2 │ export {createApi} from "@reduxjs/toolkit/query/react";
        ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
okikio commented 10 months ago

This is an issue with the package.json of @reduxjs/toolkit

https://unpkg.com/@reduxjs/toolkit@1.9.7/query/react/package.json

{
    "name": "@reduxjs/toolkit-query-react",
    "version": "1.0.0",
    "description": "",
    "main": "../../dist/query/react/index.js",
    "module": "../../dist/query/react/rtk-query-react.esm.js",
    "unpkg": "../../dist/query/react/rtk-query-react.umd.min.js",
    "author": "Mark Erikson <mark@isquaredsoftware.com>",
    "license": "MIT",
    "types": "../../dist/query/react/index.d.ts",
    "sideEffects": false
}

The version mismatch confuses bundlejs, I'm thinking about what the best solution for this would be? 🤔

markerikson commented 10 months ago

Hmm. Yeah, part of the problem here is that this is actually all one package, with multiple entry points. That package.json file only exists so that alternate entry points work with Node's existing resolution algorithm.

The version numbers in those are pretty irrelevant, but technically I could update those as part of the build process, I guess.

RTK 2.0 has proper ESM and package.exports support, so that should improve things.

But, both these attempts error in different ways:

export { configureStore } from "@reduxjs/toolkit@2.0.0-beta.4";
export {createApi} from "@reduxjs/toolkit@2.0.0-beta.4/query/react";
// or
// export {createApi} from "@reduxjs/toolkit/query/react@2.0.0-beta.4";
export { Provider } from "react-redux";
okikio commented 10 months ago

I'll look into way to fix that behavior so it still bundles

markerikson commented 2 months ago

Hi, this looks like it's still an issue. Any chance it could be looked at? Thanks!

okikio commented 2 months ago

Sorry, about that, this should now be fixed, please give it a try

Note: I still need to apply the fix to the API

markerikson commented 2 months ago

Awesome, that works now - thank you!

image