2

I'm using WebStorm to build a Node.js app. I'm using TypeScript.

When I use "require" statements I get this warning:

unresolved function or method require

It happens only in TypeScript files. In js files there's no problem. The code works BTW, it's only a warning.

I've found many questions about this warning but they all about JavaScript, and in my project js files have no problem with the "require" statement, just the ts files.

Any help will be profoundly appreciated!

3 Answers 3

6

I've found many questions about this warning but they all about JavaScript, and in my project js files have no problem with the "require" statement, just the ts files.

In TypeScript you need to declare everthing you are using to prevent you from mistaken misspellings.

Get node.d.ts from DefinitelyTyped : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node/node.d.ts

More

https://basarat.gitbooks.io/typescript/content/docs/types/migrating.html

Sign up to request clarification or add additional context in comments.

3 Comments

Perfect answer. Thank you!
how can you solve this without importing the node.d.ts? I just want to have a few lines to add to my file.
@SuperUberDuper: Importing of node.d.ts is not required. Just do npm install @types/node --save-dev and webstorm should resolve "require()"
2

Javascript Library open WebStorm preferences => languages and frameworks => Javascript => Libraries.In comparison with me,you should have no “Nodejs core”,what is marked by red circle. resolve this question,you open WebStorm preferences => languages and frameworks => Javascript ,change your current Javascript version,then switch your right Javascript version.Do as above,you should have resovled this question

1 Comment

How would the OP know what the "right Javascript version" is? I'm not sure that your answer provides enough information for the OP to address their issue, and understand the solution.
0

open WebStorm preferences => languages and frameworks => Node.js & NPM . check "Coding assistance for Node.js"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.