Are Vue Electron applications unable to use ECMAScript class properties?

Currently, I am in the process of developing a Vue application that operates within Electron. To simplify the setup procedure, I have opted to utilize vue-cli along with the helpful vue-cli-plugin-electron-builder.

The project was initially set up by executing:

vue create

During the feature selection process, I made sure to include 'babel'.

Following this, I proceeded to add the necessary Electron packages by running:

vue add electron-builder

In addition, a class was created in the file 'foo.js':

export class Foo {
  foo = "Hello";
}

Subsequently, when attempting to import this class into the generated 'main.js' file (where the Vue instance is initialized), I utilized:

npm run electron:serve

This command effectively launches the application in Electron without any errors, meeting my expectations.

However, upon trying to import the 'Foo' class into the generated 'background.js' file (where the Electron windows are instantiated) and running 'npm run electron:serve', an error message is displayed:

ERROR  Failed to compile with 1 errors

 error  in ./src/foo.js

Module parse failed: Unexpected token (2:6)
You may need an appropriate loader to handle this file type, as currently no loaders are configured. See https://webpack.js.org/concepts#loaders
| export class Foo {
>   foo = "Hello";
| }
|

 @ ./src/background.js 9:0-28
 @ multi ./src/background.js

After consulting the README on the GitHub page for @vue/babel-preset-app, it appears that the 'plugin-proposal-class-properties' should be used. This seems like the suitable solution for this issue.

I also attempted to configure the 'vue.config.js' file using 'configureWebpack' and specified the use of babel-loader with the Vue preset. Despite these efforts, the same error persists.

Is there a method available for utilizing class properties when importing a module into the 'background.js' file?

Answer №1

After referencing the documentation for the vue-cli-plugin-electron-builder, I was able to discover a solution to my issue.

The setup involves utilizing the webpack-chain package in order to tailor electron-specific bundling configurations.

Instead of employing configureWebpack within vue.config.js, I implemented my configuration following the webpack-chain example:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      chainWebpackMainProcess: config => {
        config.module
          .rule("compile")
          .test(/\.js$/)
          .exclude.add(/(node_modules|dist_electron)/)
          .end()
          .use("babel")
          .loader("babel-loader")
          .options({
            presets: ["@vue/cli-plugin-babel/preset"]
          });
      }
    }
  }
};

As a result, the imports began functioning as intended.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the new Bootstrap equivalent for btn-group-justify?

Could someone help me align the 3 radio options in this HTML code to make them appear justified? I have already tried using d-flex and btn-group-justify without success. If anyone could provide a sample using only Bootstrap 4.1+, it would be greatly appre ...

Panel floating with Bootstrap framework

I have created a unique two-column layout using Bootstrap, utilizing the col-md-6 class. The layout consists of a row with a panel at the top containing a table, a left column panel displaying a list of media items, and a right column panel containing text ...

What are the steps to retrieve raw messages from Gmail using Node.js?

I'm attempting to retrieve the complete email message data, including body content, using the raw format option specified in the gmail api reference. Unfortunately, it doesn't appear to be functioning correctly. Here is the code I'm using: ...

Creating test doubles using Sinon allows you to effectively block the execution of the original function

I am currently engaged in JavaScript unit testing using Mocha and Sinon. My goal is to verify if a specific method is called under certain conditions. However, I have encountered difficulties purely testing the method call. To clarify, I aim to replace th ...

What is the best way to utilize Object.keys for formatting incoming data?

Here is the data I have: const langs = { en: ['One', 'description'], pl: ['Jeden', 'opis'], }; I want to convert it into this format: const formattedData = { name: { en: "One", ...

Eliminating every instance of the character `^` from a given string

I am encountering an issue with a particular string: "^My Name Is Robert.^". I am looking to remove the occurrences of ^ from this string. I attempted using the replace method as follows: replyText.replace(/^/g, ''); Unfortunately, thi ...

Display the selection order in the index for multiple items in the Vuetify component v-select

Hey everyone, I'm new to Vue.js and I've encountered a roadblock with a basic issue. I created a multiple v-select (Vuetify component) that allows users to select one or more items from a list. <v-select dark class="mb- ...

ways to access the data property in Vue.js

In my attempt to increase traffic, I have identified that I have had 4 visits as shown in my console { "status": true, "visits": 4 } How can I retrieve the "visits": 4 from data:[] const options = { ...

The AngularJS $rootscope $destroy event is not being triggered, resulting in timeouts not being cancelled

Below is the code snippet that I am currently working with: function initialize() { var defer = $q.defer(); var deferTimer = $q.defer(); var cancelTimeout = $timeout(function() { if (defer !== null) { ctrlr.setProcessingParameters('X ...

Issues with logging in using Facebook Javascript SDK on Chrome and Safari (webkit) - Unauthorized Javascript intervention

I have encountered a problem that seems to defy the solutions proposed for similar questions on other platforms. My local development site is hosted on a virtual machine at: Upon loading the index.php page, I have a specific javascript code running (with ...

Caution: The session_start() function encountered an issue while trying to access session data for the user stored at C:xampp mp

After updating Joomla to version 3.8.5, everything was running smoothly. However, I recently had to reinstall XAMPP and now encountering the following issue: native.php if (!session_start()) { throw new RuntimeException(' ...

Angular UI Grid: Transferring rows between dual grids

Recently, I decided to give angular-ui-grid a try (http://ui-grid.info/) and attempted to implement a feature that involves moving rows between two different grids. I found a solution for this on the kendo grid here: http://jsfiddle.net/OnaBai/2qXKy/. How ...

Is there a directive in AngularJS that allows for binding HTML templates using ng-bind-html

I'm working on a directive that has the ability to use dynamic templates with expressions inside them. The challenge I face is if I use ng-bind-html, the expression won't be evaluated properly. On the other hand, using ng-bin-template results in ...

The TextBox will alter its color following an incorrect submission

I am struggling to create a bootstrap form that will change the color of the borders to red after incorrect submission. The issue I am facing is that the textbox always remains in red. Does anyone have any suggestions for setting the textbox borders to red ...

Utilize a JavaScript array containing numerous objects to transmit information to the Google Tag Manager and populate the Google data

Is there a way to send multiple product information to the Google data layer as an array of objects, rather than just one combined object? I currently have a script that sends all fields in one object, but I need each product to have its own object within ...

How can we retrieve the user ID in Node.js MySql so that it can be utilized in subsequent queries post login?

I am currently in the process of developing a web application using node.js and MySQL as my database. I have configured a login system, but I am unsure about how to determine what information should be displayed on certain pages based on user data. In ad ...

The UDP/datagram server is unable to retrieve packets from the remote computer

After developing a UDP listening server within an Electron application using the UDP/datagram module, I encountered a perplexing issue. Despite successfully binding the socket to my local IP address (not loopback) and port 8500, test packets sent from the ...

Sending a message from a Vue.js application to Contact Form 7 using the Wordpress REST API - a step-by-step guide

I recently added Contact-Form-7 to my WordPress admin panel, which generated an API Endpoint for me at http://localhost/wordpress/wp-json/contact-form-7/v1/contact-forms Attempting to send a POST request to this endpoint using the following code: data() ...

Issue encountered while attempting to install cmake-js/fastcall

Having trouble installing cmake-js/fastcall: npm install fastcall Encountering the following error: ERR! OMG There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio. .... npm ERR! Windows_NT 6.1.7601 npm ERR! argv " ...

The Three.js IEWebGL Plugin

After developing a code that successfully rotates a cube with trackball using the three.js library and webgl, I encountered compatibility issues when trying to run it on Internet Explorer 10. Despite downloading IeWebgl to assist in making it run on IE10 ...