在另一个文件中使用时找不到module.exports值

时间:2017-07-05 22:24:31

标签: javascript node.js ecmascript-6 eslint es6-modules

不知道为什么,我可以导入此文件并在我的测试文件中使用expect就好了,但是我收到了一个eslint错误:

error  expect not found in '../../testImports' import/named

这是我导出的地方testImports.js

import chai from 'chai'
const expect = require('chai').expect
import { BrowserRouter } from 'react-router-dom'
import { jsdom } from './jsdom'

module.exports = {
  BrowserRouter,
  expect,
  jsdom
}

我正在导入文件:import { expect } from '../../testImports'

1 个答案:

答案 0 :(得分:0)

问题是eslint-plugin-import仅取决于ES6模块系统导出,而不是ES5。它们意味着同样的事情,插件只是没有抓住它。由于插件没有看到您导出任何内容,它会报告错误,但是您的代码没有任何实际错误。如果您想摆脱错误,只需使用ES6的export

export {
  BrowserRouter,
  expect,
  jsdom
};