2017-05-25 49 views
2
/* index.js */ 
import { React } from 'react'; 
import { USER, ORDER } from './StaticVariable'; 
class AgentList extends React.Component { 
    render() { 
    const useInfo = USER; 
    const orderId = ORDER; 
    return <Info useInfo={useInfo} orderId={orderId} /> 
    } 
} 

/* StaticVariable.js */ 
export const ORDER = 12347600; 

似乎babel-loader不会抛出错误。并且该页面也不会控制错误。 我应该怎么做才能避免导入未定义的模块或变量?使用eslint?如何防止导入ES2015中不存在的名称?

+0

使用一个编辑器来指出这些错误给你。你在用什么编辑器? – 2017-05-25 07:41:53

回答

0

这个eslint插件完全符合你的需求:eslint-plugin-import

您可以安装它:

npm install eslint-plugin-import -g 

而且在.eslintrc配置插件:

{ 
    ... 
    "extends": [ 
    ... 
    "plugin:import/errors", 
    "plugin:import/warnings" 
    ], 
    "plugins": [ "import" ], 
    "rules": { 
    "import/named": 2, 
    "import/default": 2 
    ... 
    } 
} 

规则,你需要使用有:

确保命名进口对应于指定出口在远程文件中。 (named

在给定默认导入的情况下,确保存在默认导出。 (default

相关问题