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

Unable to transform arrow inside class property #156

Closed
4 tasks done
adminy opened this issue May 7, 2023 · 8 comments
Closed
4 tasks done

Unable to transform arrow inside class property #156

adminy opened this issue May 7, 2023 · 8 comments
Labels
question Further information is requested

Comments

@adminy
Copy link

adminy commented May 7, 2023

Warning
Similar issue found here: #60
Taking bytecode plugin out from the config, fixes the problem.

Describe the bug

When I run electron-vite dev --watch, the application runs fine.
But when its run with electron-vite build I get the following:

vite v4.3.5 building for production...
 277 modules transformed.
rendering chunks (3)...[vite:bytecode] unknown file: Unable to transform arrow inside class property
  12144 |     }
  12145 |     // conditionally set private methods related to TTL
> 12146 |     #updateItemAge = () => { };
        |                      ^^^^^^^^^
  12147 |     #statusTTL = () => { };
  12148 |     #setItemTTL = () => { };
  12149 |     /* c8 ignore stop */
 0 bundles compiled into bytecode.
 built in 1.66s
error during build:
SyntaxError: unknown file: Unable to transform arrow inside class property
  12144 |     }
  12145 |     // conditionally set private methods related to TTL
> 12146 |     #updateItemAge = () => { };
        |                      ^^^^^^^^^
  12147 |     #statusTTL = () => { };
  12148 |     #setItemTTL = () => { };
  12149 |     /* c8 ignore stop */
    at File.buildCodeFrameError (/Users/adminy/project/node_modules/@babel/core/lib/transformation/file/file.js:205:12)
    at NodePath.buildCodeFrameError (/Users/adminy/project/node_modules/@babel/traverse/lib/path/index.js:105:21)
    at hoistFunctionEnvironment (/Users/adminy/project/node_modules/@babel/traverse/lib/path/conversion.js:171:20)
    at NodePath.arrowFunctionToExpression (/Users/adminy/project/node_modules/@babel/traverse/lib/path/conversion.js:121:7)
    at PluginPass.ArrowFunctionExpression (/Users/adminy/project/node_modules/@babel/plugin-transform-arrow-functions/lib/index.js:18:16)
    at newFn (/Users/adminy/project/node_modules/@babel/traverse/lib/visitors.js:149:21)
    at NodePath._call (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:45:20)
    at NodePath.call (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:35:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:81:31)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitSingle (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:65:19)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:109:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:87:52)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitMultiple (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:61:17)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:107:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:87:52)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitSingle (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:65:19)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:109:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:87:52)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitSingle (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:65:19)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:109:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:87:52)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitMultiple (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:61:17)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:107:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:87:52)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitMultiple (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:61:17)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:107:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at NodePath.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/path/context.js:87:52)
    at TraversalContext.visitQueue (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:86:16)
    at TraversalContext.visitSingle (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:65:19)
    at TraversalContext.visit (/Users/adminy/project/node_modules/@babel/traverse/lib/context.js:109:19)
    at traverseNode (/Users/adminy/project/node_modules/@babel/traverse/lib/traverse-node.js:18:17)
    at traverse (/Users/adminy/project/node_modules/@babel/traverse/lib/index.js:49:34)
    at transformFile (/Users/adminy/project/node_modules/@babel/core/lib/transformation/index.js:81:29)
    at transformFile.next (<anonymous>)
    at run (/Users/adminy/project/node_modules/@babel/core/lib/transformation/index.js:24:12)
    at run.next (<anonymous>)
    at transform (/Users/adminy/project/node_modules/@babel/core/lib/transform.js:22:41)
    at transform.next (<anonymous>)

My electron.vite.config.mjs looks like this:

import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
export default defineConfig({
  main: { plugins: [externalizeDepsPlugin(), bytecodePlugin()] },
  preload: { plugins: [externalizeDepsPlugin(), bytecodePlugin()] },
  renderer: {
    plugins: [svelte()],
    define: { global: {}, 'process.env': process.env }
  }
})

I thought it was a babel issue babel/babel#15613
but now I'm not so sure...

Electron-Vite Version

1.0.22

Electron Version

24.2.0

Vite Version

4.3.4

Validations

@adminy adminy added the bug Something isn't working label May 7, 2023
@alex8088 alex8088 added question Further information is requested and removed bug Something isn't working labels May 8, 2023
@alex8088
Copy link
Owner

alex8088 commented May 8, 2023

Bytecode protection requires converting arrow functions to normal functions.

class A {
  handle = (x = 0) => {
    console.log(x);
  };
}

The above example has a problem with conversion. This is a related bug of babel. The solution is to use normal functions or as follows:

class A {
  async handle(x = 0) {
    console.log(x);
  };
}

@alex8088 alex8088 closed this as completed May 8, 2023
@adminy
Copy link
Author

adminy commented May 8, 2023

But I don't even have classes in my code ...

@alex8088
Copy link
Owner

alex8088 commented May 8, 2023

Install related modules in deps.

@philjones88
Copy link

Install related modules in deps.

can you expand please, i have the same issue but it is from an NPM package.

@philjones88
Copy link

in my case, it's this package https://github.com/megahertz/electron-log/blob/master/src/node/EventLogger.js#L8 that breaks my build

@zhimingzhang123
Copy link

in my case, it's this package megahertz/electron-log@master/src/node/EventLogger.js#L8 that breaks my build

@philjones88 So, how did you ultimately solve it?

@duyixian1234
Copy link

in my case, it's this package megahertz/electron-log@master/src/node/EventLogger.js#L8 that breaks my build

@philjones88 So, how did you ultimately solve it?

I mannuly modified source code for electron-log, and it worked
node_modules\electron-log\src\node\EventLogger.js
image
image

@zhimingzhang123
Copy link

@duyixian1234 thank you, it works well😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants