Webstorm 7 cannot recognize node API methods - javascript

I just installed WebStorm. I'm working on a small Node.js app.
I've attached the Node.js source code, and when I click on the Node.js settings, I can see that it can recognize my various node modules, etc.
I'm having two issues:
Unresolved variable or type: WebStorm doesn't seem to recognize simple API methods (exports, require).
No code insight for…: If I call require('winston'), it tells me that it has no code insight. (Is there a way I can add the source code?)

For 2018 and later versions of WebStorm:
In Settings -> Languages & Frameworks -> Node.js and NPM, check Coding assistance for Node.js:
In older Webstorm versions, this was called Enable Node.js Core library.
If you still see unrecognized Node symbols even with that option enabled, unckeck it, restart WebStorm, then right click on the warning and choose Enable Node.js coding assistance or just check the option again. Watch for WebStorm to show it's Indexing files. (Just had this happen today - looks like a WebStorm bug, and what I just wrote fixed the situation.)

For WebStorm 7 thru 10 (on OSX)…
WebStorm → Preferences → Languages & Frameworks → Javascript → Libraries
Select "Node.js Globals" and "Node.js vXXX Core Modules".

I use WebStorm 2020 and I had everything enabled but WebStill though showed that module.exports is unknown function. Then I turned off NodeJS.core library and NodeJS code assistance, applied and then turned them on again. And suddenly it started to work.

As I've answered on the WebStorm says console is an unresolved variable question, to solve these problems on the new Webstorm versions, you need to enable the Coding assistance for Node.js.
To do this, go on the Settings > Languages & Frameworks > Node.js and NPM and click on the Coding assistance for Node.js option, and then click OK to save:
This will all Node.js unresolved variables and functions.
Update
On the new Webstorm versions, just going above error and clicking in More Actions... (or ALT+ENTER) and selecting
Enable Node.js coding assistance will solve this.

Working with WebStorm and Node.js these two code-segments regularly gave me "false positive" warnings:
FALSE POSITIVE WARNING CASE 1:
module.exports = ...
That gave me the warning "Element is not exported". I was able to get rid of the warning caused by that by putting this above the "module.exports = ..."
/** #namespace module.exports **/
FALSE POSITIVE WARNING CASE 2:
let something = global.something ;
That gave me the warning "Unresolved variable or type global". I was able to eliminate the warning caused by that by putting this above it:
/** #namespace global **/
I now put the following on top of my .js- or .mjs-files to be executed by Node.js, and get rid of warnings referring to these variables or properties:
/** #namespace global **/
/** #namespace console **/
/** #namespace process **/
/** #namespace Buffer **/
/** #namespace process.stdin **/
/** #namespace module.exports **/
I am using WebStorm 2022.2.3

Updating to Webstorm 8 or higher will fix your require methods problem. As posted earlier by checking if Settings > JavaScript > Libraries > Node.js are all checked will fix your problem

Related

PhpStorm: Unresolved variables, methods & functions for NodeJS modules

I just started a new NodeJS application in PhpStorm which uses some external packages. Unfortunately I see a lot of Unresolved variable or Unresolved function or method warnings:
Obviously this is very distracting. Can I somehow manually tell the IDE to load some definition files of the external packages I use (e.g. mongoose in this example)?
If I find no other solution I'd simply disable those inspections which is kind of a bad "fallback" since they usually provide some good hints for typos etc.
Solution:
I had 2 different node_modules directories in my project:
project\client\node_modules\...
project\server\node_modules\...
Both were marked as excluded. I simply removed the excluded mark (right-click on the folder in the project tree). PhpStorm shows correct auto completion now and the Unresolved warnings are gone.
If you have jetbrains suite, It's better to use webstorm for nodejs application.
However, if you want to keep phpstorm. You can use a jshint module for global variables declaration, and use jsdoc for variable instance :
/**
* Description
* #type {Schema}
* #property {object} methods
*/
var Schema;
-- EDIT --
Have you set up your phpstorm as the jetbrains doc ?
Work on nodejs with phpstorm

Flow type checker errors in node_modules/*

I've initialized flow project with flow init in fresh https://github.com/davezuko/react-redux-starter-kit project.
When Flow does it check, it finds several errors in node_modules.
Errors are happening in /* flow */ annotated library files.
It looks like this:
node_modules/editions/source/index.js:33
33: const {name, editions} = require(packagePath)
^^^^^^^^^^^^^^^^^^^^ The parameter passed to require() must be a literal string.
node_modules/fbjs/lib/Deferred.js.flow:60
60: Promise.prototype.done.apply(this._promise, arguments);
^^^^ property `done`. Property not found in
474: declare class Promise<+R> {
^ Promise. See lib: /private/tmp/flow/flowlib_d34ebcf/core.js:474
node_modules/fbjs/lib/shallowEqual.js.flow:29
29: return x !== 0 || 1 / (x: $FlowIssue) === 1 / (y: $FlowIssue);
^^^^^^^^^^ identifier `$FlowIssue`. Could not resolve name
Should I make Flow ignoring those files? I assume it may affect type checking correctness.
Both fbjs and editions are written using Flow. They each have .flowconfig files with various configurations. All the errors that you are seeing are due to your .flowconfig being configured slightly differently.
The easiest fix is to modify your .flowconfig to support the things that edition and fbjs are using.
Adding module.ignore_non_literal_requires=true to the [options] section should fix the first error. By default Flow will error if you pass a variable to require(), since Flow wants to understand the dependency graph. This option relaxes this requirement.
Adding ./node_modules/fbjs/flow/lib to the [libs] section should fix the second error. fbjs uses a non-standard version of Promise, but it does ship with a library definition for that version of Promise.
Adding suppress_type=$FlowIssue to the [options] section should fix the third error. This option just aliases the any type to $FlowIssue. It makes it more clear when you're using any to suppress an error.
In the future, the Flow team imagines that Flow users will choose to ignore node_modules/ altogether and instead rely on library definitions from https://github.com/flowtype/flow-typed/, so we're investing in definitions and tooling around flow-typed. This will avoid the sort of situation that you're running into.
I personally like to ignore everything under node_modules by doing this.
[ignore]
.*/node_modules/.*
I then use flow-typed to install or stub all imports
https://github.com/flowtype/flow-typed
You can ignore node_modules by adding below line in .flowconfig in the section [declarations]
<PROJECT_ROOT>/node_modules/.*
Refer below screenshot as well
Below is link of document reference
https://flow.org/en/docs/config/declarations/
It also says
Often third-party libraries have broken type definitions or have type
definitions only compatible with a certain version of Flow. In those
cases it may be useful to use type information from the third-party
libraries without typechecking their contents.

Embedding Chakra javascript engine failed to initialize COM interfaces

I just compiled ChakraCore and run Hello World Sample.
when I built ChakraCore there was no error found.
But when I run HelloWorld sampl System.Runtime.InetropServices.SEHException occured at ChakraHost.Hosting.Native.JsCreateContext(JavaScriptRuntime runtime, JavaScriptContext& newContext).
It said external component has thrown an exception.
So I enabled native code debugging and found assertion failure in ChakraCore and Assert message is like below.
AssertMsg(false, "Failed to initialize COM interfaces, verify correct version of globalization dll is used.");
Then I searched for system.globalization.dll file and found the file in multiple folders.
I copied it into C:\windows\SysWOW64 and ran regsvr32 system.globalization.dll.
I got below message from the run.
The module "system.globalization.dll" was loaded but the entry-point DllRegisterServer was not found.
Make sure that "system.globalization.dll"is a valid DLL or OCS file and theny try again.
I don't know what to do now. I have spend hours to solve this problem.
Can anyone help me figure this out please?
Thanks,
Here is what I did to get it working.
Build ChakraCore from Visual Studio 2015. I used debug and x64
Copy ChakraCore/Build/VcBuild/bin/x64_debug.ChakraCore.dll to Chakra-Samples\ChakraCore Samples\Hello World\C#\HelloWorld\bin
Go to HelloWorld solution properties and set Platform target to x64
Add breakpoint in Main method of HelloWorld press F5.
In my case the failing line was always:
// Create a runtime.
Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null, out runtime);
After taking the actions mentioned above I get the HelloWorld sample to run.
Hope this helps.

VSCode TypeScript lint

People, who develop TypeScript used Visual Studio Code? I'm trying to use it too. But I have no validation(ts-lint) warnings or errors. I just got such messages on build:
ts-lint start
src/constants/type.ts[22, 2]: file should end with a newline
src/constants/type.ts[6, 5]: misplaced opening brace
ts-lint end
Example:
1 == 2
Such expression in JS file will message me that it will be better to use 1 === 2.
But this expression in TS file will work and not even show any warning.
What can I do to enable such validation in TypeScript, while typing?
Just had the exact same problem and seem to have resolved by adding "typescript" to the eslint.validate array in workspace settings
{
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript"
]
}
Should you be new to VSCode. F1 => type "settings" => from the dropdown select either "user settings" (any project for that logged in user) or "workspace settings" (that one project only) => paste the above object on the right pane (or extend the existing object should there be one)
Please update to 0.8.0 version of vs code, just released. JavaScript Linting as you Type is now supported. https://code.visualstudio.com/updates
I did some experimentation running into a similar problem and found that I had a jsconfig.json file laying around that was created prior to converting code over to TypeScript. After removing/renaming that file and restarting VSCode it appears that my TypeScript compiler errors are now showing up as the error output when doing a build in VSCode as opposed to seemingly unrelated errors about unresolved imports.
I'm not sure if this is the same problem you're experiencing but hopefully it's of some help to you or somebody else.

Error updating JScript IntelliSense with jquery-1.3.2.min.js

Any idea..
Warning 15 Error updating JScript IntelliSense: ********\jquery\jquery-1.3.2.min.js: Object doesn't support this property or method # 18:9345 '*******' 1 1 projname
Note: Actual File path of file which contain the javascript is replaced with **
Project Name is replaced with projname
Please let me know...
Thanks in advance
Are you using V 2008? May be JS Intellisense engine is unable to work with minified version.
Use vsdoc files instead - find one for your jquery version here: http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2-vsdoc2.js&can=2&q= (rename it as jquery-1.3.2-vsdoc.js). You need VS 2008 SP1 for vdoc files to work.
See this blog post announcing vsdoc based js intellisense support. Check this FAQ to trouble-shoot related issues.

Categories