Helpful Eslint Rules

When you work with remix you should use this eslintrc config to avoid common mistakes.

Introduction

Did you ever encounter this error message and wondered why it happened? If you use @remix-run/node you should let eslint help you to avoid this error.

.eslintrc.js
1/** @type {import('@types/eslint').Linter.BaseConfig} */
2module.exports = {
3  ... // other config
4  rules: {
5    'no-restricted-imports': [
6      'error',
7      {
8        paths: [
9          {
10            name: 'express',
11            importNames: ['json'],
12            message: 'Please use "@remix-run/node" instead'
13          }
14        ]
15      }
16    ]
17  }
18}

Then you get the following error when you try to import the "wrong" json module.

1error  'json' import from 'express' is restricted. Please use "@remix-run/node" instead  no-restricted-imports