Plugin can't resolve some functions when working with electron (typescript)
See original GitHub issueThe 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.
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:
- Created 2 years ago
- Comments:8 (3 by maintainers)
@Treverix does the same happen if you use it like this? I don’t have such an issue…
According to Electron’s type declarations, the ipcRendered is located under the renderer namespace:
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)