question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chalk with ESLint & Airbnb Base

See original GitHub issue

I am using the latest version of Chalk and using ESLint with the Airbnb Base. Unfortunately, when I import chalk, am getting the following linting error: Unable to resolve path to module ‘chalk’. eslint(import/no-unresolved)

The module loads and works fine but it is throwing that linting error and it is driving me nuts.

package.json for DevDependencies and ESLint config:

  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.13.0",
    "@typescript-eslint/parser": "^5.13.0",
    "eslint": "^8.10.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-prettier": "^4.0.0",
    "nodemon": "^2.0.15",
    "prettier": "^2.5.1",
    "typescript": "^4.6.2"
  },
  "eslintConfig": {
    "extends": [
      "airbnb-base",
      "plugin:@typescript-eslint/recommended",
      "plugin:prettier/recommended"
    ],
    "env": {
      "node": true
    }
  },

app.js where I call Chalk:

import express, { json, urlencoded } from 'express';
import helmet, { contentSecurityPolicy } from 'helmet';
import morgan from 'morgan';
import Debug from 'debug';
import chalk from 'chalk';

console.log(`${chalk.red('Hello!'});

I could use some guidance as to why it’s throwing this for Chalk. I am not getting that error for my other Packages. Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jmcombscommented, Mar 8, 2022

@Qix- it looks like the issue is because "main": "./source/index.js", is missing from package.json.

	"repository": "chalk/chalk",
	"funding": "https://github.com/chalk/chalk?sponsor=1",
	"type": "module",
	"main": "./source/index.js",
	"exports": "./source/index.js",

Once main is added to package.json linting passes.

The linting error pops up due to package import-js/eslint-plugin-import. There is an open issue Rule import/no-unresolved raise false positive when there is no main field in the package.json #2132 but the maintainer of that package is adamant that proper etiquette is to include both main and exports in package.json. Main entry point export has also been referenced as justification for this requirement from the NodeJS website.

Is this something you would be willing to add or would you prefer me to submit a PR with a fix? (I am new to this)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[eslint-config-airbnb] Unexpected top-level property ... - GitHub
Hi, I've been trying to install version 15.0.1, but I'm encountering the following error: ESLint configuration is invalid: - Unexpected ...
Read more >
eslint-config-airbnb-base - npm
Airbnb's base JS ESLint config, following our styleguide. Latest version: 15.0.0, last published: a year ago.
Read more >
13. Install and add ESLint Airbnb base config from ... - YouTube
In this video, we will see how to install and add the ESLInt config Airbnb base from NPM and extend the Airbnb in...
Read more >
E24: Improve code quality using ESLint in IntelliJ
One of the most important steps you can take to improve the quality of your code is to use a quality assurance tool...
Read more >
Credits - Enduvo
No. MODULE NAME/ COMPONENT PAGE LICENSE 1 Activity Indicator Progress Circle Homepage Show License 2 Assimp (see TriLib) Homepage Show License 3 async Homepage Show License...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found