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.

Plugin can't resolve some functions when working with electron (typescript)

See original GitHub issue

The following screenshot shows a case where the plugin fails to find dependencies. This is, to be fair a nasty special case.

Here I use svelte for electron browser windows. It’s like usual scripts, only that we need to require the electron libraries that we need on the client side scipts. This require is not the common NodeJS require but an electron require function that is placed on windows. The syntax though looks exactly like commonjs.

Now when we import a svelte file on the main script (App.ts), it works fine and the plugin understands the required ipcRenderer function. But it fails after that level. For every svelte file imported by any other svelte file, it does not work anymore (see screenshot).

There is a simple workaround: when we just import all svelte files on App.ts also, the errors disappear from the editors.

image

App.ts

import App from './App.svelte';

// import it here to solve the 'error' on that component
// import ImportedComponent from './ImportedComponent.svelte';

export default new App({target: document.body});

App.svelte

<script lang:ts>
    const {ipcRenderer} = require('electron');  // this require is in fact windows.require, a function placed on windows by electron
    import ImportedComponent from './ImportedComponent.svelte';

    // works at this level
    ipcRenderer.invoke('some-channel');
</script>

<ImportedComponent/>

ImportedComponent.svelte

<script lang="ts">
  const {ipcRenderer} = require('electron');  // this require is in fact windows.require, a function placed on windows by electron

  // shows an error here although it works
  ipcRenderer.invoke('some-channel');

</script>

Environment

Webstorm: 2021.1.2 OS: Windows 10 Typescript: 4.3.2 Svelte: 3.38.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
r00t3gcommented, Jun 10, 2021

@Treverix does the same happen if you use it like this? I don’t have such an issue…

import { ipcRenderer } from 'electron/renderer';

According to Electron’s type declarations, the ipcRendered is located under the renderer namespace: image

0reactions
tomblachutcommented, Jul 23, 2021

Hi @Treverix , could you check if this not-so-secret-anymore attachment fixes the problem? (2021.2 required) svelte-intellij-0.21.0-alpha.zip

(same file as in #222)

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Module not found: Error: Can't resolve 'electron-is-dev'" in ...
I have webpack.config.js file that I used in another project, so I copy it and edit a little. And It worked! I compared...
Read more >
electron-store - npm
Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc. Latest version: 8.1.0, ...
Read more >
Parcel
parcel index.html Server running at http://localhost:1234 Build failed. @parcel/core: Cannot resolve 'ract' from './index.js' /dev/app/index.js:1:19 > 1 ...
Read more >
TypeScript debugging with Visual Studio Code
json and the VS Code Node.js debugger can't map your TypeScript source code to the running JavaScript. Turn on source maps and rebuild...
Read more >
Common Configuration - electron-builder
Because in a configuration file you cannot use JavaScript, can be specified as a path to file or module id. Function must be...
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