Skip to content

crypto flagged as false positive on no-nodejs-modules rule #3202

@alvis

Description

@alvis

Description:
When using the no-nodejs-modules rule from eslint-plugin-import, the cross-environment crypto module is flagged as a violation. Even though it can be a Node.js core module, so technically it's not wrong, but it can also be available from most browser environments and hence violate the intent of the rule that prevent any node js module import are used in browser environment.

Example Code:

import * as crypto from 'crypto';

Expected Behavior:
crypto should not be flagged by no-nodejs-modules if the context is ambiguous since it is also available in browser environments. The rule should differentiate between modules that are strictly Node.js core modules (e.g. node:crypto) and those that are also valid in browser contexts.

Actual Behavior:
Do not import Node.js builtin module "crypto"eslint[import/no-nodejs-modules](https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-nodejs-modules.md)

Environment:

  • eslint-plugin-import: 2.32.0
  • ESLint: 9.31.0

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