简体   繁体   English

WebStorm自动导入 - “需要”而不是“导入”

[英]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. 在Node.js项目上工作当我的Node.js不支持import语句时,我得到了使用ES6导入的建议( Alt + Enter )。 Can I add suggestions that use require? 我可以添加使用require的建议吗? Auto import saves so much time... 自动导入节省了大量时间......

自动导入

The manipulateName method definition: manipulateName方法定义:

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

and ... 和......

module.exports = {
    manipulateName,
 ...
}

Please make sure that Node.js Core library is enabled for your project ( Preferences | Languages & Frameworks | Node.js and NPM, Node.js Core library ). 请确保为您的项目启用了Node.js核心库( 首选项|语言和框架| Node.js和NPM,Node.js核心库 )。

See Missing require() statement inspection ( Preferences | Editor | InspectionsJavaScript | Node.js ) description: 请参阅缺少require()语句检查( Preferences | Editor | InspectionsJavaScript | Node.js )说明:

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.

Webstorm 2019.2. Webstorm 2019.2。
In my case I tried to enable "Coding assistance for Node.js" but the following happened: 在我的情况下,我尝试启用“Node.js的编码协助”,但发生了以下情况:
Check "Coding assistance for Node.js" --> Ok --> Re-open "Node.js and NPM" --> Coding Assistance is not checked. 选中“Node.js的编码帮助” - >确定 - >重新打开“Node.js和NPM” - >不检查编码辅助。

I did the following: 我做了以下事情:
1. Help --> Find Action --> Registry --> search for "nodejs.core.library.use.typings" --> disable it. 1.帮助 - >查找操作 - >注册表 - >搜索“nodejs.core.library.use.typings” - >禁用它。
2. File --> "Invalidate and Restart" 2.文件 - >“无效并重新启动”
3. Go To Terminal --> type: 3.转到终端 - >键入:

  /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" 4.设置 - >“Node.js和NPM” - >选中“Node.js的编码辅助”

Solved! 解决了! Check also Jetbrains Issue 检查Jetbrains问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM