250

I'm using WebStorm 7 for Firefox Add-on SDK development.

WebStorm shows a warning: "Unresolved function or method" for require().

I want to get rid of the warning.

var pageMod = require("sdk/page-mod");

NOTE:I already configured JavaScript-library (refer /lib/sdk globals).

Environment:

  • WebStorm 7.0.2
  • Windows 7 64bit
  • Firefox Add-on SDK 1.15beta1
Makyen
  • 31,849
  • 12
  • 86
  • 121
skatsumata
  • 2,614
  • 2
  • 11
  • 7

13 Answers13

382

Do you mean that require() is not resolved? You need to either add require.js to your project or enable Node.js Globals predefined library in Settings/Languages and Frameworks/JavaScript/Libraries.

(Edited settings path by @yurik)

In WebStorm 2016.x-2017.x: make sure that the Node.js Core library is enabled in Settings (Preferences) | Languages & Frameworks | Node.js and NPM

In IntelliJ 2018.3.2+ go to Settings (Preferences) | Languages & Frameworks | Node.js and NPM and enable Coding assistance for Node.js

lena
  • 90,154
  • 11
  • 145
  • 150
  • Thank you lena. and sorry my english poor.(>_<;) I want to cleanup warning on webstorm-editor. (script execution is no problem. ) Firefox-Addon-SDK conforms commonjs, but not uses node.js. "require" method defined /app-extension/bootstrap.js I set bootstrap.js to External Libraries, but not clear "unresolved" warning. let require = cuddlefish.Require(loader, module); function loadSandbox(uri) { let sandbox = ... sandbox.require = function (id) { return Object.freeze({ ... }); }; return sandbox; – skatsumata Nov 26 '13 at 09:27
  • 12
    Useful answer! BTW, in my webstorm 9, The location is: *Language & Frameworks -> Javascript -> Libraries* ; Another approach is to search for "Libraries" – Paul Ho Nov 10 '14 at 02:41
  • 1
    In Webstorm 9, you can also right-click on "require", and choose "Use Javascript Library->Node.js Globals" – Josh Noe Oct 25 '15 at 19:20
  • Enable the NodeJS plugin if 'Node.js Globals' is missing from the library list. – i0x539 Aug 01 '17 at 17:00
  • I tried everything in this tread and nothing worked, but when I updated to the latest webstorm, hey presto, no more errors! Give it a go, I'm using Webstorm 2017.3 (the problem was happening in Webstorm 11) and I no longer get the problem – FrodmanG Dec 08 '17 at 12:09
  • Sometimes you have to turn that option off, save the settings, then turn it on again for the error to go away. – jlh Dec 25 '18 at 13:53
  • 4
    FYI: I had to turn my node assist OFF, invalid caches and restart WebStorm and then turn it back ON to get it working. WebStorm 2018.3.5 – Reactgular Feb 28 '19 at 15:47
  • I had to do what @Reactgular said above. WebStorm 2021.2 – calvin Oct 12 '21 at 16:09
236

Webstorm 11 and 2016.2.3

Enable Node.js Core library in Webstorm settings.

enter image description here

enter image description here

enter image description here

Andrzej Rehmann
  • 12,360
  • 7
  • 39
  • 38
  • I just wanted to add on that I had the same problem and although my core library was already enabled, going to the settings screen seemed to fix the problem. – Rob Rose Mar 19 '16 at 19:22
  • 1
    didn't work for me using typescript with the latest version of node and webstorm. Still on the hunt for a fix for us angular2 people. Usage inside a component definition `styles: [require('./app.component.css')]` – a_dreb Jun 23 '16 at 06:07
  • I still have the error in the compiler error TS2304: Cannot find name 'require'. – SuperUberDuper Oct 21 '16 at 12:12
  • @SuperUberDuper You should replace 'require' with `import {*} from 'node module'` and specify `"target": "CommonJS"` inside **tsconfig.json** – Bhoomtawath Plinsut Jan 05 '17 at 08:05
  • Worked as soon as I enabled it in Webstorm preferences (not the project settings) – U_D Jun 04 '17 at 07:54
  • weird, not working in webstorm 2022.1.1 – Kasra May 27 '22 at 08:34
60

After spending an hour trying to get this to work using all solutions found online, this finally did the trick!

File -> Invalidate Caches/Restart...

M.Vanderlee
  • 2,847
  • 2
  • 19
  • 16
47

In PHPStorm, it's a bit easier: you can just search for NPM in settings or:

File > Settings > Language & Frameworks > Node.js and NPM

Then click the enable button (apparently in new versions, it is called "Coding assistance for Node").

Zane
  • 4,652
  • 1
  • 29
  • 26
18

Working with Intellj 2016, Angular2, and Typescript... the only thing that worked for me was to get the Typescript Definitions for NodeJS

Get node.d.ts from DefinitelyTyped on GitHub

Or just run:

npm install @types/node --save-dev

Then in tsconfig.json, include

"types": [
     "node"
  ]
SuperUberDuper
  • 9,242
  • 9
  • 39
  • 72
TetraDev
  • 16,074
  • 6
  • 60
  • 61
  • 4
    Thank You! I feel like I've been searching for ages! Just installing @types/node calmed down WebStorm; I'll see about the compiler later. – Kesarion Oct 06 '16 at 14:52
  • Thank you, this worked for me. For me, it used to work using the accepted answer here, but it somehow started conflicting as I added new libraries. This fixed my problem again – kioleanu Feb 04 '19 at 10:45
14

In WebStorm 2018.3 a bit different interface enter image description here

Sergey S
  • 889
  • 12
  • 18
7

On WebStorm 2016.3

  1. Press ALT+F12 (open terminal)

  2. Run this command:

    npm install require.js
    
Pang
  • 9,564
  • 146
  • 81
  • 122
GalBenEvgi
  • 71
  • 1
  • 3
5

For WebStorm 2019.3 File > Preferences or Settings > Languages & Frameworks > Node.js and NPM -> Enable Coding assitance for NodeJs

Note that the additional packages that you want to use are included.

Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50
4

Disable JetBrains Inspections and get the ESLint plugin.

The only thing that File | Invalidate caches and restart does for me is reset it long enough to trick me into thinking the error is gone. Once the inspections run again the error comes back like a gift that keeps on giving.

I saved myself all that frustration by disabling all JetBrains inspections (Editor > Inspections > uncheck JavaScript) Then I installed the ESLint plugin.

The inspection that causes "Unresolved function method" can be turned off by going to JetBrains inspections (Editor > Inspections > JavaScript) and searching for "Unresolved Javascript" and turning off "Unresolved Javascript function" and "Unresolved Javascript variable"

I killed them all and have edited my code hassle free ever since.

Shanimal
  • 11,517
  • 7
  • 63
  • 76
3

Ok, Here I have seen a lot of answers already given, I want to add some more that are fixed unresolved function/method/variable warning.

That is resolved "unresolved function or method for 'require' and some other warning"

Go -> Preferences-> Languages & Frameworks -> Node.js and NPM, then checkmark the "Coding assistance for Node.js"

If you still see this type of warning, unresolved variable or something like that, you can manually disable these warnings by followings.

Go -> Preferences-> Editor-> Inspections-> JavaScript-> General.  

and you will find a list and just unchecked what warning you want to disable and then apply.

Md Alamin
  • 1,084
  • 11
  • 19
2

Another solution that helped me a lot is to update all libs in "Node.js and NPM". You need just mark all libs and click blue arrow - 'update' enter image description here

0

None of the above solutions worked for me. Something crazy happened. There was a tsconfig.json sitting in one of my directories. Once I deleted that it started working.

Josh Woodcock
  • 2,683
  • 1
  • 22
  • 29
-2

File->Settings->Languages & Frameworks->JavaScript

Instruction

Dmitry Matrosov
  • 412
  • 4
  • 5