简体   繁体   中英

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 . Now I see

Prefer default export import/prefer-default-export

for this line: export const Tasks = new Mongo.Collection('tasks'); in imports/api/tasks.js file. It contains also some Meteor methods. Here it is full source code: 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 :

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:

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

UPDATE :

If you want to keep the rule, then you need to export Tasks as default like so:

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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