Guy
Guy

Reputation: 13306

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,
 ...
}

Upvotes: 9

Views: 4044

Answers (2)

chenop
chenop

Reputation: 5143

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

Upvotes: 1

lena
lena

Reputation: 93738

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.

Upvotes: 11

Related Questions