aidenybai / million

Optimize React performance and make your React 70% faster in minutes, not months.
https://million.dev
MIT License
16.09k stars 561 forks source link

ReferenceError: require is not defined in Reactjs Ts Vite #819

Closed shoaib-blocksdev closed 8 months ago

shoaib-blocksdev commented 9 months ago

What version of million are you using?

^2.6.4

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

i'm using vite and typescript getting this error on browser console

Uncaught ReferenceError: require is not defined
    at main.tsx:3:15

vite.config.ts

import { defineConfig } from 'vite';
import million from 'million/compiler';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import path from 'path'

export default defineConfig({
  plugins: [million.vite({ auto: false }),tsconfigPaths({ root: 'src'}),react()],
  server: {
    port: 3000,
  },
  resolve: {
    alias: [
      { find: '@', replacement: path.resolve(__dirname, 'src') },
    ],
  },
});

main.tsx file


import ReactDOM from 'react-dom/client'
import {RecoilRoot} from 'recoil';

import App from './App'
import './index.scss';
import './styles/App.scss';
import './styles/upgrades.scss';
import Boundary from "./components/Boundary";

ReactDOM.createRoot(document.getElementById('root')!).render(
    <>
        <RecoilRoot>
            <Boundary>
                <App/>
            </Boundary>
        </RecoilRoot>
    </>
)

What's the expected result?

there should be no error in console when adding millionjs in vite.config.ts

Link to Minimal Reproducible Example

https

Participation

github-actions[bot] commented 9 months ago

Thanks for opening this issue! A maintainer will review it soon.

tobySolutions commented 8 months ago

Hmm, this is weird. Can you please provide a repro @shoaib-blocksdev.

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.