electron-vite-vue icon indicating copy to clipboard operation
electron-vite-vue copied to clipboard

[Help] Issue with porting an existing app over

Open Stanzilla opened this issue 3 years ago • 16 comments

Describe the problem you Confuse

Hey there, I'm currently trying to port an existing application over to this template and running into an issue where the content won't load.

[plugin:vite:import-analysis] Failed to resolve import "${moduleName}" from "node_modules/@electron/remote/dist/src/main/server.js?v=b01c5d3c". Does the file exist?
/home/stan/projects/personal/WeakAurasCompanion/node_modules/@electron/remote/dist/src/main/server.js:11:45
9  |  import * as __require_for_vite_LxV6Rj from "../common/get-electron-binding";
10 |  import * as __require_for_vite_gQPFem from "@electron/remote/main";
11 |  import * as __require_for_vite_GEtNgH from "${moduleName}";
   |                                              ^
12 |  import * as __require_for_vite_lMpJfA from "${moduleName}";
13 |  import * as __require_for_vite_lJsWyZ from "electron";
    at formatError (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39055:46)
    at TransformContext.error (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39051:19)
    at normalizeUrl (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:58329:26)
    at async TransformContext.transform (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:58478:57)
    at async Object.transform (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39292:30)
    at async doTransform (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:50012:29

The code is in this branch here https://github.com/WeakAuras/WeakAuras-Companion/tree/v5

Any hint or help would be appreciated :)

More detail (optional)

Add any other context or screenshots.

Stanzilla avatar Jun 11 '22 04:06 Stanzilla

9  |  import * as __require_for_vite_LxV6Rj from "../common/get-electron-binding";
10 |  import * as __require_for_vite_gQPFem from "@electron/remote/main";
11 |  import * as __require_for_vite_GEtNgH from "${moduleName}";
   |                                              ^
12 |  import * as __require_for_vite_lMpJfA from "${moduleName}";
13 |  import * as __require_for_vite_lJsWyZ from "electron";

This BUG from @originjs/vite-plugin-commonjs, I saw your code with a lot of the require. You can try use vite-require plugin. If there are similar problems, you can be in vite-require by the issues, that is I wrote :)

caoxiemeihao avatar Jun 12 '22 00:06 caoxiemeihao

vite-require

That gives me

[plugin:vite-plugin-require] p is not iterable
/home/stan/projects/personal/WeakAurasCompanion/packages/renderer/src/App.vue
    at /home/stan/projects/personal/WeakAurasCompanion/node_modules/@babel/parser/lib/index.js:11545:43
    at Array.some (<anonymous>)
    at hasPlugin (/home/stan/projects/personal/WeakAurasCompanion/node_modules/@babel/parser/lib/index.js:11541:18)
    at validatePlugins (/home/stan/projects/personal/WeakAurasCompanion/node_modules/@babel/parser/lib/index.js:11580:7)
    at getParser (/home/stan/projects/personal/WeakAurasCompanion/node_modules/@babel/parser/lib/index.js:16594:5)
    at Object.parse (/home/stan/projects/personal/WeakAurasCompanion/node_modules/@babel/parser/lib/index.js:16565:12)
    at TransformContext.<anonymous> (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite-plugin-require/dist/index.js:56:40)
    at step (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite-plugin-require/dist/index.js:33:23)
    at Object.next (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite-plugin-require/dist/index.js:14:53)
    at /home/stan/projects/personal/WeakAurasCompanion/node_modules/vite-plugin-require/dist/index.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite-plugin-require/dist/index.js:4:12)
    at TransformContext.transform (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite-plugin-require/dist/index.js:48:20)
    at Object.transform (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39292:53)
    at async doTransform (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chu

Stanzilla avatar Jun 12 '22 01:06 Stanzilla

vite-require is not vite-plugin-require

caoxiemeihao avatar Jun 12 '22 01:06 caoxiemeihao

vite-require is not vite-plugin-require

ooh my bad, sorry.

[plugin:vite-require] Unexpected token (1:0)
/home/stan/projects/personal/WeakAurasCompanion/packages/renderer/src/components/LandingPage.vue:1:0
1  |  <template>
   |  ^
2  |    <div id="wrapper">
3  |      <div
    at Parser.pp$4.raise (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:33561:13)
    at Parser.pp$9.unexpected (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:30855:8)
    at Parser.pp$5.parseExprAtom (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32936:10)
    at Parser.pp$5.parseExprSubscripts (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32728:19)
    at Parser.pp$5.parseMaybeUnary (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32694:17)
    at Parser.pp$5.parseExprOps (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32621:19)
    at Parser.pp$5.parseMaybeConditional (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32604:19)
    at Parser.pp$5.parseMaybeAssign (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32571:19)
    at Parser.pp$5.parseExpression (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:32534:19)
    at Parser.pp$8.parseStatement (/home/stan/projects/personal/WeakAurasCompanion/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:31045:45

Stanzilla avatar Jun 12 '22 01:06 Stanzilla

Put vite-require after @vitejs/plugin-vue

caoxiemeihao avatar Jun 12 '22 01:06 caoxiemeihao

When using require("sharp"); this now yields

Uncaught ReferenceError: Cannot access 'resolve' before initialization
    at path.js:4:26
(anonymous) @ path.js:4

in .vite-plugin-electron-renderer/path.js

When using import sharp from "sharp"; I get

Uncaught SyntaxError: The requested module '/@fs/home/stan/projects/personal/WeakAurasCompanion/node_modules/sharp/lib/index.js?v=75990b4a' does not provide an export named 'default' (at gif2tga.js:3:8)

Stanzilla avatar Jun 12 '22 01:06 Stanzilla

import * as sharp from 'sharp'

caoxiemeihao avatar Jun 12 '22 02:06 caoxiemeihao

import * as sharp from 'sharp'

Uncaught ReferenceError: Cannot access 'resolve' before initialization at path.js:4:26 (anonymous) @ path.js:4

Stanzilla avatar Jun 12 '22 02:06 Stanzilla

I'm looking at this problem, a little wait for me, oh :)

caoxiemeihao avatar Jun 12 '22 02:06 caoxiemeihao

I submitted a PR, hoping to help you.

https://github.com/WeakAuras/WeakAuras-Companion/pull/1441

I try fixed all BUG 🐞, but finally I got the problem. This seems to have nothing to do with the plugin.

image

caoxiemeihao avatar Jun 12 '22 04:06 caoxiemeihao

Oh, you're awesome, thank you so much, will check it out!

Stanzilla avatar Jun 12 '22 04:06 Stanzilla

Alright, merged it, thanks again! The error is curious since the actual code did not change in that refactor but I'll see if I can figure out what causes it.

Stanzilla avatar Jun 12 '22 05:06 Stanzilla

@Stanzilla ha-ha! I saw that you are the author of cmder and I am the user of cmder. cmder is awesome. 🎉

caoxiemeihao avatar Jun 12 '22 06:06 caoxiemeihao

@Stanzilla ha-ha! I saw that you are the author of cmder and I am the user of cmder. cmder is awesome. 🎉

Hah thank you!

Stanzilla avatar Jun 12 '22 06:06 Stanzilla

@caoxiemeihao Hey there, I figured it out! It's image requires that cause this, example:

<img :src="require(`@/assets/social-icons/wago.svg`)" class="logo" title="Wago" />

Stanzilla avatar Jun 14 '22 01:06 Stanzilla

<img :src="require(`@/assets/social-icons/wago.svg`)" class="logo" title="Wago" />

The require() finally convert to import and then will promotion to the top by vite-require, exmaple:

import * as __require2import__id__ from '@/assets/social-icons/wago.svg'
↓
<img :src="__require2import__id__" class="logo" title="Wago" />

caoxiemeihao avatar Jun 14 '22 03:06 caoxiemeihao