Skip to content

no-unpublished-require throws a TypeError when "." or "./" is required #48

@fasttime

Description

@fasttime

The rule n/no-unpublished-require sometimes throws a TypeError when require(".") or require("./") occurs in the code.

This only happens under certain circumstances:

  • The node environment is set
  • The file that contains the require is included in the files field in package.json.
  • There is no file named index.js, or if package.json defines a different file in the main field, that file does not exist.

The smallest repro I've come up with:

package.json

{
  "files": [
    "*.js"
  ],
  "devDependencies": {
    "eslint": "latest",
    "eslint-plugin-n": "latest"
  }
}

.eslintrc

{
    "env": {
        "node": true
    },
    "plugins": [
        "n"
    ],
    "rules": {
        "n/no-unpublished-require": "error"
    }
}

foo.js

require('.');

Running npm installand then npx eslint . in the project folder prints an error message like this:

Oops! Something went wrong! :(

ESLint: 8.22.0

TypeError: path must not be empty
Occurred while linting /home/user/my-project/foo.js:1
Rule: "n/no-unpublished-require"

DEMO LINK


I could try to fix this if desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions