Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

325
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.