Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

326
Vistas
Failed to load resource (file not found) Electron js cannot import or export

Failed to load resource: net::ERR_FILE_NOT_FOUND

I am using latest version of npm, node.js and electron.

My html file calls upon a terrautils.js:

<script type="module" src="./terrautils.js"></script>

My terrautils.js file has first line as:

import { LCDClient, Coin } from './node_modules/@terra-money/terra.js';

Which is the link to an npm module that I want to use, and I have it installed and have confirmed that the folder is really there using file explorer. I also know the module works perfectly file, because this issue only happens when I run using npm start but when I run using node terrautils.js and swap from using import to using require, it works perfectly fine.

This is something to do with electron I think, and not sure what to do. My main.js has createWindow function like:

function createWindow (site) {
  var win = new BrowserWindow({
    width: 700,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: true,
      contextIsolation: true,
      devTools: true,
    }
  })

  win.loadFile(site)
}

I do not care about security, I just want this to work. Thank you.

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solution:

Change html invoking of the js file to this instead:

    <script>
        require('./terrautils.js')
    </script>

dont know how it works, but it does.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos