gpt4 book ai didi

javascript - Webstorm ES6 named import getting cannot resolve symbol 错误

转载 作者:可可西里 更新时间:2023-11-01 01:18:27 27 4
gpt4 key购买 nike

我在 Webstorm 中使用 ES6 命名导入声明时出现错误:

import { nodes } from 'utils/dom';

我在“节点”上收到“无法解析符号”错误

此外,当我尝试像这样导出为命名导出时:

export {
write: document.write.bind(document),
node: document.querySelector.bind(document),
nodes: document.querySelectorAll.bind(document)
};

我也有错误。我将 eslint 与 babel-eslint 解析器一起使用。问题是这在 Sublime Text 3 中很有用,但由于某种原因在 Webstorm 中无法进行错误检查。

我假设这是因为除了 Eslint webstorm 正在做其他代码检查。

知道如何抑制它并仅将 eslint 与 babel-eslint 解析器一起使用吗?

任何建议将不胜感激

最佳答案

I get "cannot resolve symbol" error on "nodes"

是因为标准 Node 代码中的 utils/dom 表示“在名为‘utils’的模块中查找 dom.js。您已通过使用 webpack 的 moduleDirectories 属性覆盖了此行为, 但 WebStorm 不知道那是什么。要使 WebStorm 正确解析 utils/dom,您需要将 utils 文件夹添加为您的 webstorm 项目中的库配置。

您的 export 语法不正确。 ES6 导入/导出语法与对象 100% 无关,在您的示例导出中,您使用的是对象语法。 import { nodes } 正在请求名为 nodes 的导出。您可以通过多种方式编写您拥有的导出:

export const write = document.write.bind(document);
export const node = document.querySelector.bind(document);
export const nodes = document.querySelectorAll.bind(document);

或者,如果你喜欢多行 var/let/const

,你可以折叠它们
export const write = document.write.bind(document),
node = document.querySelector.bind(document),
nodes = document.querySelectorAll.bind(document);

甚至

const write = document.write.bind(document);
const node = document.querySelector.bind(document);
const nodes = document.querySelectorAll.bind(document);


export {write, node, nodes};

关于javascript - Webstorm ES6 named import getting cannot resolve symbol 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31624567/

27 4 0