Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm Auto import - "require" instead of "import from"

Working on a Node.js project I get suggestions (Alt + Enter) to import using ES6 when my Node.js does not support the import statement. Can I add suggestions that use require? Auto import saves so much time...

auto import

The manipulateName method definition:

const manipulateName = (layout, method) => {
    layout.name = method(layout.name);
    return layout;
}

and ...

module.exports = {
    manipulateName,
 ...
}
like image 348
Guy Avatar asked Feb 18 '18 04:02

Guy


2 Answers

Please make sure that Node.js Core library is enabled for your project (Preferences | Languages & Frameworks | Node.js and NPM, Node.js Core library).

See Missing require() statement inspection (Preferences | Editor | InspectionsJavaScript | Node.js) description:

Checks that all modules are referenced through "require()".
Suggests inserting the "require()" call.
Works only in files in the scope of "Node.js Core" JavaScript library.
like image 161
lena Avatar answered Oct 16 '22 19:10

lena


Webstorm 2019.2.
In my case I tried to enable "Coding assistance for Node.js" but the following happened:
Check "Coding assistance for Node.js" --> Ok --> Re-open "Node.js and NPM" --> Coding Assistance is not checked.

I did the following:
1. Help --> Find Action --> Registry --> search for "nodejs.core.library.use.typings" --> disable it.
2. File --> "Invalidate and Restart"
3. Go To Terminal --> type:

  /usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js install @types/node --ignore-scripts

4. Settings --> "Node.js and NPM" --> checked "Coding Assistance for Node.js"

Solved! Check also Jetbrains Issue

like image 22
chenop Avatar answered Oct 16 '22 19:10

chenop