Javascript 名为导入获取的Webstorm ES6无法解决符号错误

Javascript 名为导入获取的Webstorm ES6无法解决符号错误,javascript,frontend,webstorm,ecmascript-6,babeljs,Javascript,Frontend,Webstorm,Ecmascript 6,Babeljs,使用ES6命名导入声明时,Webstorm中出现错误: import { nodes } from 'utils/dom'; “节点”上出现“无法解析符号”错误 另外,当我尝试以命名导出时,如下所示: export { write: document.write.bind(document), node: document.querySelector.bind(document), nodes: document.querySelectorAll.bind(document) };

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

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解析器吗

如有任何建议,将不胜感激

“节点”上出现“无法解析符号”错误

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

您的
导出
语法不正确。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};

很难说这是否是直接相关的,但要想知道如何解析导入,您还可以转到
首选项>目录
,并将文件夹设置为
资源根目录
(或右键/上下文单击文件夹并将其设置为该目录)

这可能需要完成,例如,当您配置了Webpack来解析某些子目录时,您的项目结构可能是:

/
  /docs
  /src
    /containers
      /app
        App.js
    /components
      /header
        Header.js
在这种情况下,Webstorm希望在
App.js
中导入如下内容:

import Header from '../../../components/header/Header'
而对于Webpack,如果您已将
src
添加为要解决的模块,则可以执行以下操作,Webstorm目前不理解这些操作,因此将其添加为资源根解决了问题

import Header from 'components/header/Header'

参考资料:

您的导出是错误的,导出不是这样工作的。但不确定是否需要导入。在这种情况下,什么是
utils
?这不是标准路径,因为它不是相对文件路径。您是否有自定义模块解析逻辑?您可以导出对象,然后从“path”导入{property},局部变量属性将被分配导出属性的值。语法没有问题。它很好用。它不应该是相对文件路径。我使用webpack和babel loader。我不需要相对文件路径,因为我在webpack配置中使用ModuleDirectory来搜索文件夹集。所以底线是它是有效的。这是正确的问题是为什么webstorm将其显示为incorrect@VladimirNovick那你是怎么解决这个问题的?