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

Import "InitializePayload" fails in esbuild (e.g. when using Vite) #223

Open
Naartti opened this issue Aug 26, 2021 · 3 comments · May be fixed by #224
Open

Import "InitializePayload" fails in esbuild (e.g. when using Vite) #223

Naartti opened this issue Aug 26, 2021 · 3 comments · May be fixed by #224

Comments

@Naartti
Copy link

Naartti commented Aug 26, 2021

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
react-localize-redux cannot be built in Vite for react because there is an import of InitializePayload from LocalizeProviders which does not exist in localize. I checked react-localize-redux in my node_modules and there is no InitializePayload in localize.

node_modules/react-localize-redux/es/LocalizeProvider.js:10:131: error: No matching export in "node_modules/react-localize-redux/es/localize.js" for import "InitializePayload"
    10 │ ...age, initialize as initializeAC, INITIALIZE, InitializePayload } from './localize';

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

  1. Start a new Vite project and choose React and TypeScript.
  2. Install react-localize-redux.
  3. Import anything from react-localize-redux.
  4. Start dev server and see the error in the terminal.

What is the expected behavior?
Should be able to build the code.

Which versions of react and react-localize-redux are you using?
react: 17.0.2
react-localize-redux: 3.5.3

Naartti added a commit to Naartti/react-localize-redux that referenced this issue Aug 26, 2021
Remove type import and declare it again. The bundler does not know to remove InitializePayload from the import, making builds fail for Vite (esbuild).
Fixes ryandrewjohnson#223
@Naartti Naartti linked a pull request Aug 26, 2021 that will close this issue
@gerhardcit
Copy link

Also run into this issue in an older system we have to fix up.
Is there an alternative package to use rather that this? @Naartti , how did you solve it in the end?

@Naartti
Copy link
Author

Naartti commented Jan 17, 2023

@gerhardcit I did a fork of this package and included it locally in my project ( #224 ).

@raspberric
Copy link

raspberric commented May 15, 2024

In case someone stumbles here for a quick fix, I managed to do the following:

optimizeDeps: {
      esbuildOptions: {
        plugins: [
          {
            name: 'patch-react-localize-redux',
            setup(build) {
              build.onLoad(
                {
                  // this made it work on windows, double check it works for you
                  filter: /react-localize-redux[\/\\]es[\/\\]localize.js/,
                },
                async (args) => {
                  const fileContents = await fs.readFile(args.path, 'utf8');
                  const patchedContents =
                    fileContents + '\nexport const InitializePayload = {};';
                  return {
                    contents: patchedContents,
                  };
                },
              );
            },
          },
        ],
      },
    },

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 a pull request may close this issue.

3 participants