question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error while running inside of Electron

See original GitHub issue

I am writing a mapping application that is going to be running inside of Electron. I am trying to use this to load the ArcGIS API for JavaScript modules but I am getting the following error:

ERROR Error: Uncaught (in promise): AssertionError: path must be a string
AssertionError: path must be a string
    at Module.require (module.js:497)
    at require (internal/module.js:20)
    at Object.dojoRequire (index.js:44)
    at esri-loader.service.js:41
    at new ZoneAwarePromise (zone.js:776)
    at EsriLoaderService.loadModules (esri-loader.service.js:39)
    at esri4-map.service.js:15
    at ZoneDelegate.invoke (zone.js:365)
    at Object.onInvoke (core.es5.js:4145)

The line of code that this is failing on is:

window['require'](modules, callback);

Because of the fact that this is running inside of Electron and therefor is loading in a NodeJS process the require() function accepts a string as an argument rather than an array of strings.

I have created a repo to demonstrate this issue. Instructions for running this application inside of Electron can be found in its README.

One possible solution to this issue is to use RequireJS for loading modules. This is generally not meant to be used in a NodeJS environment but should provide the API that you are looking for with the window['require'](modules, callback) call.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
andygupcommented, Apr 25, 2017

@kgs916 I’ve seen that error before when trying to run a require statement in the main process.

I haven’t tried esri-loader in Electron, but in a few prototypes that I built I didn’t seem to need it.

Here’s a simple example you can try out really fast using electron-quick-start.

Run the following commands in console:

git clone https://github.com/electron/electron-quick-start
cd electron-quick-start
npm install && npm start

The quickstart app should launch. If it does then control-c in the console to exit the app.

Change the index.html file to this:


<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.3/esri/css/main.css">
    <script src="https://js.arcgis.com/4.3/"></script>
  </head>
  <body>
    <h1>Hello World Part 2!</h1>
    <!-- All of the Node.js APIs are available in this renderer process. -->
    We are using Node.js <script>document.write(process.versions.node)</script>,
    Chromium <script>document.write(process.versions.chrome)</script>,
    and Electron <script>document.write(process.versions.electron)</script>.

    <div id="viewDiv"></div>

  </body>

  <script src="index.js"></script>
  <script>
    // You can also require other files to run in this process
    require('./renderer.js')
  </script>
</html>

And create index.js and copy the following content in:

require([
     "esri/Map",
     "esri/views/MapView",
     "dojo/domReady!"
 ], function(Map, MapView) {

     console.log("Require() loaded.");

     var map = new Map({
         basemap: "streets"
     });

     var view = new MapView({
         container: "viewDiv",
         map: map,
         zoom: 4,
         center: [15, 65]
     });

 });

The last step is to run npm start again and you should see a map.

image

1reaction
TheKeithStewartcommented, Apr 30, 2017

@tomwayson

I like the name. I have renamed the repo to ng-cli-electron-esri and updated it to use the latest esri-loader. Thanks for getting release out there!

One more change that I want to make to this example before I consider it good-to-go is to use the angular2-esri-loader so that it matches the example gist. I’ve submitted a PR to update the angular2-esri-loader to the latest esri-loader as well https://github.com/tomwayson/angular2-esri-loader/pull/13.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An unhandled error occurred inside electron-rebuild
To use electron-rebuild it has mentioned following requirements ;. What are the requirements? Node v6.0.0 or higher is required.
Read more >
Build Instructions | Electron
If you see a prompt for Username for 'https://chrome-internal.googlesource.com': when running gclient sync on Windows, it's probably because the ...
Read more >
Creating a Desktop App with Electron and Angular | Buddy
In this article, we'll learn how to build cross-platform desktop apps for Windows, Linux and macOS using Electron, TypeScript and Angular.
Read more >
A Comprehensive Guide to Building and Packaging an ...
Building and Packaging an Electron App wasn't as straight forward as I had hoped. This guide aims to help you navigate the complexities...
Read more >
A Company banned me because I made their Electron App ...
Run Tinkerwell (electron) inside Docker ... Tinkerwell (electron) running inside Docker ... line 3: trails and error, while trying to start electron, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found