Skip to content

import { app } from '@electron/remote'; in vue3 setup throws an error #168

Open
@bluelemonade

Description

@bluelemonade

If got some error:

inside background.js

require('@electron/remote/main').initialize();

in the App.vue File

import fs from 'fs';
import pathModule from 'path'
import { app } from '@electron/remote';
import { onMounted, ref } from 'vue'; // onMounted,



export default {
  name: "app",

  setup() {

    const path = ref(app.getAppPath());
    console.log(path.value);

    onMounted(() => {
      
      try {
        fs.writeFileSync('myfile.txt', 'the text to write in the file', 'utf-8');
      } catch (e) {
        alert('Failed to save the file !');
      }
    });
	

these are the errors, when I comment the path and app lines out I can write a file in my working directory. I think the problem is the import of the app.

runtime-core.esm-bundler.js:41 [Vue warn]: Unhandled error during execution of setup function 
  at <App>
warn @ runtime-core.esm-bundler.js:41
app.js:470 Uncaught Error: @electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.
    at IpcMainImpl.eval (webpack:///./node_modules/@electron/remote/dist/src/main/server.js?:318:61)
    at IpcMainImpl.emit (node:events:514:28)
    at WebContents.<anonymous> (node:electron/js2c/browser_init:2:89402)
    at WebContents.emit (node:events:514:28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions