简体   繁体   English

如何使用React教程修复流星中的eslint错误

[英]How to fix eslint errors in meteor with react tutorial

I've followed meteor tutorial , and when I finished I've decided to install eslint . 我遵循了流星教程 ,当我完成后,我决定安装eslint Now I see 现在我明白了

Prefer default export import/prefer-default-export 首选默认导出导入/首选默认默认导出

for this line: export const Tasks = new Mongo.Collection('tasks'); 对于这一行: export const Tasks = new Mongo.Collection('tasks'); in imports/api/tasks.js file. imports/api/tasks.js文件中。 It contains also some Meteor methods. 它还包含一些流星方法。 Here it is full source code: tasks.js . 这是完整的源代码: tasks.js

I was trying to fix this eg. 我试图解决这个问题。 with

const Tasks = new Mongo.Collection('tasks');
export { Tasks as default };

But then browser stopped rendering the view. 但是随后浏览器停止渲染视图。 Here is the server/main.js content, which imports tasks.js : 这是server/main.js内容,该内容导入tasks.js

import '../imports/api/tasks.js';

How can I fix lint error without breaking applications functionality? 如何在不破坏应用程序功能的情况下修复棉绒错误?

You could add an .eslintrc file to your project root and adapt the rule: 您可以将.eslintrc文件添加到项目根目录并修改规则:

{"rules": {"import/prefer-default-export": ["off"]}}

UPDATE : 更新

If you want to keep the rule, then you need to export Tasks as default like so: 如果要保留规则,则需要将“ Tasks导出为默认值,如下所示:

const Tasks = new Mongo.Collection('tasks');
export default Tasks;

Now you have to change all the imports in the rest of your codebase from a named import to a default import. 现在,您必须将代码库其余部分中的所有imports都从命名导入更改为默认导入。 The named import looks like this 命名的导入看起来像这样

import { Tasks } from '/imports/api/tasks';

see eg here , whereas the new default import has to look like this 请参见例如此处 ,而新的默认导入必须如下所示

import Tasks from '/imports/api/tasks';

This should do it. 这应该做。 Let me know if it works for you. 请让我知道这对你有没有用。

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

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