Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm 2016.3 + Electron: Unresolved function or method

I am playing around with Electron and WebStorm as part of a project preparation and I am struggling with different problems. Therefore I want to start simple by creating very basic stuff and working my way up.

So I have a very simple project setup in WebStorm and my first Electron app is running. But WebStorm keeps saying that it cannot resolve function names.

enter image description here

Electron and electron-prebuilt are added to the package.json and Node.js coding assistance is enabled. Therefore require('electron') is recognised correctly.

I saw the blog entry by JetBrains on how to start with Electron in WebStorm and found also another similar answer here on StackOverflow.

JetBrains' blog entry

StackOverflow answer

It is said, that one should add github-electron to the JavaScript library from the communitie-stubs repositories. But these seems outdated, as there is no github-electron anymore and all other electron entries are ambiguous.

enter image description here

enter image description here

So my question is: How to setup WebStorm for plain JS ES6 correctly, beginning by eliminating the "unresolved" messages?

like image 332
Martin Majewski Avatar asked Nov 29 '16 19:11

Martin Majewski


1 Answers

So, after digging into the topic more and more and climbing the steep learning curve, I finally found the answer by myself.

Here we go:

  1. Go to WebStorm's Preferences / Languages & Frameworks / TypeScript
  2. Make sure Use TypeScript Service is enabled

enter image description here

  1. Open up WebStorm's Terminal panel (as it will automatically point to your project's working directory) and install the type definitions for TypeScript via NPM:

    enter image description here

    npm install @types/electron

    You don't need to use the --save / --save-dev tags, as the types are needed solely for WebStorm's code assistance and have no impact on your project.

    enter image description here

    You'll get a new entry inside your node_modules folder containing the type definitions.

    enter image description here

    And that's it. WebStorm does not show any unresolved function or method messages for this particular module anymore.

    enter image description here

    This works for theoretically every other module, as long as there are type definitions available. But chances are good, as there are a lot of them. Way more than what WebStorm's JavaScript library download functionality offers.

Have a nice day, everyone!

Martin

like image 55
Martin Majewski Avatar answered Nov 15 '22 09:11

Martin Majewski