react-timeline-editor icon indicating copy to clipboard operation
react-timeline-editor copied to clipboard

No matching export in "node_modules/react-virtualized/dist/es/WindowScroller/WindowScroller.js" for import "bpfrpt_proptype_WindowScroller"

Open assadi-dev opened this issue 1 year ago • 8 comments

I have this error when i import Timeline on vite project

assadi-dev avatar Nov 29 '23 21:11 assadi-dev

i fix it on remove image

on onScroll.js file

assadi-dev avatar Nov 29 '23 21:11 assadi-dev

This is the fix

In vite.config.js

const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`

function reactVirtualized(): PluginOption {
  return {
    name: 'flat:react-virtualized',
    // Note: we cannot use the `transform` hook here
    //       because libraries are pre-bundled in vite directly,
    //       plugins aren't able to hack that step currently.
    //       so instead we manually edit the file in node_modules.
    //       all we need is to find the timing before pre-bundling.
    configResolved: async () => {
      const require = createRequire(import.meta.url)
      const reactVirtualizedPath = require.resolve('react-virtualized')
      const { pathname: reactVirtualizedFilePath } = new url.URL(reactVirtualizedPath, import.meta.url)
      const file = reactVirtualizedFilePath
        .replace(
          path.join('dist', 'commonjs', 'index.js'),
          path.join('dist', 'es', 'WindowScroller', 'utils', 'onScroll.js'),
        )
      const code = await fs.readFile(file, 'utf-8')
      const modified = code.replace(WRONG_CODE, '')
      await fs.writeFile(file, modified)
    },
  }
}
export default defineConfig({
   plugins: [react(), reactVirtualized().....

mcosti avatar Dec 19 '23 21:12 mcosti

thanks

assadi-dev avatar Dec 20 '23 12:12 assadi-dev

@mcosti, thank you!! this saved me lots of time.

including imports, this is what got it working for me:

import { PluginOption, defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import fs from "fs/promises";
import { createRequire } from 'module';

const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`

function reactVirtualized(): PluginOption {
  return {
    name: 'flat:react-virtualized',
    // Note: we cannot use the `transform` hook here
    //       because libraries are pre-bundled in vite directly,
    //       plugins aren't able to hack that step currently.
    //       so instead we manually edit the file in node_modules.
    //       all we need is to find the timing before pre-bundling.
    configResolved: async () => {
      const require = createRequire(import.meta.url)
      const reactVirtualizedPath = require.resolve('react-virtualized')
      const { pathname: reactVirtualizedFilePath } = new URL(reactVirtualizedPath, import.meta.url)
      const file = reactVirtualizedFilePath
        .replace(
          path.join('dist', 'commonjs', 'index.js'),
          path.join('dist', 'es', 'WindowScroller', 'utils', 'onScroll.js'),
        )
      const code = await fs.readFile(file, 'utf-8')
      const modified = code.replace(WRONG_CODE, '')
      await fs.writeFile(file, modified)
    },
  }
}
export default defineConfig({
   plugins: [react(), reactVirtualized().....

RobZuazua avatar Feb 01 '24 17:02 RobZuazua

i fix it on remove image

on onScroll.js file

This worked for me too!!

chiragdhunna avatar Feb 28 '24 15:02 chiragdhunna

Is there a reason we haven't added this as an update to the package or even a separate plugin ?

ry-ku avatar Apr 19 '24 08:04 ry-ku

The maintainer is not responding anymore and no one forked the project yet

mcosti avatar Apr 19 '24 09:04 mcosti

Someone has created this vite plugin to fix this issue

// vite.config.ts
import fixReactVirtualized from "esbuild-plugin-react-virtualized";

export default defineConfig({
  plugins: [react(), tsconfigPaths()],
  optimizeDeps: {
    esbuildOptions: {
      plugins: [fixReactVirtualized],
    },
  },
});

gulam-quinn avatar Jun 06 '24 11:06 gulam-quinn