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

Throw error when there is vite.config.ts file in root #3

Closed
4 tasks done
ccforeverd opened this issue Apr 29, 2022 · 6 comments
Closed
4 tasks done

Throw error when there is vite.config.ts file in root #3

ccforeverd opened this issue Apr 29, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@ccforeverd
Copy link

Describe the bug

  1. Throw error when there is vite.config.ts file in root

      The symbol "prevRefreshReg" has already been declared
      1  |  import RefreshRuntime from "/@react-refresh";let prevRefreshReg;let prevRefreshSig;if (import.meta.hot) {  if (!window.__vite_plugin_react_preamble_installed__) {    throw new Error(      "@vitejs/plugin-react can't detect preamble. Something is wrong. " +      "See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201"    );  }  prevRefreshReg = window.$RefreshReg$;  prevRefreshSig = window.$RefreshSig$;  window.$RefreshReg$ = (type, id) => {    RefreshRuntime.register(type, "/Users/zhangshuyao/Sites/electron-vite-quick-start/electron-app/src/renderer/src/App.tsx" + " " + id)  };  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;}import RefreshRuntime from "/@react-refresh";
      2  |  let prevRefreshReg;
         |      ^
      3  |  let prevRefreshSig;
      4  | 
    
  2. Type error in electron.vite.config.ts when imports vite.config.ts

      // electron.vite.config.ts
      import webViteConfig from './web.vite.config'
      export default {
        // type error: 不能将类型“UserConfigExport”分配给类型“UserConfig | undefined”。
        // 类型“Promise<UserConfig>”与类型“UserConfig”不具有相同的属性。ts(2322)
        renderer: webViteConfig
      }
    
      // web.vite.config.ts
      import { defineConfig } from 'vite'
      export default defineConfig(...)

Electron-Vite Version

1.0.2

Electron Version

18.2.0

Vite Version

2.9.6

Validations

@ccforeverd ccforeverd added the bug Something isn't working label Apr 29, 2022
@ccforeverd
Copy link
Author

Becauseof error by vite.config.ts in root, i rename it to web.vite.config.ts and then electron-vite works.

@ccforeverd
Copy link
Author

Emmm, the reson i use vite.config.ts is our old project use vite and my boss want me to make an electron app to contain it.

So i use electron-vite to create a new project, and mkdir web in root and then move old codes into it.

Then deleted most files in src/renderer/src, only stay src/renderer/src/main.tsx with code import '../../../web/main.tsx'.

And move old index.html to src/renderer/index.html and 'index.html' (in root, and script src is "./web/main.tsx").

Finally it works in electron and browser.

That's all what i have done.

And the 2 problems can't resolve so i come here for help.

Thx.

@ccforeverd
Copy link
Author

Also modify tsconfig.json.

@alex8088
Copy link
Owner

hi, @ccforeverd

first problem,

electron-vite base on vite, and vite will be automatically resolved the file named vite.congfig.{ts,js,mjs.cjs}. so the electron-vite requires the config file that cannot be named vite.config.*. You not need to use vite config file after you use electron-vite. You just need to configure in electron.vite.config.ts. I recommend you scaffold a react project using create-electron to learn how to configure .

npm create @quick-start/electron my-app --template react-ts

second problem,

it‘s a bug and i will fix it soon

Thx

@alex8088
Copy link
Owner

@ccforeverd new ver 1.0.3

@ccforeverd
Copy link
Author

Resolved! Thank you so much!
I will keep using the eletron-vite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants