Skip to content

Handle absent 'crypto' as per nodejs docs #19100

Closed
@mihailik

Description

@mihailik

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

TypeScript compiler relies on node's 'crypto' module unconditionally:

https://github.com/Microsoft/TypeScript/blob/6997e9b7316b081f8731d131139c7d7f1bba9092/src/compiler/sys.ts#L132

Whereas node's documentation for crypto module explicitly states:

Determining if crypto support is unavailable

It is possible for Node.js to be built without including support for the crypto module. In such cases, calling require('crypto') will result in an error being thrown.
let crypto;
try {
  crypto = require('crypto');
} catch (err) {
  console.log('crypto support is disabled!');
}

That means on a reduced node environment the compiler crashes unnecessarily. By unnecessarily I mean the support for crypto is already optional in the compiler:

https://github.com/Microsoft/TypeScript/blob/6997e9b7316b081f8731d131139c7d7f1bba9092/src/compiler/sys.ts#L67

https://github.com/Microsoft/TypeScript/blob/d7269f1386bb1ad4351a6f6d5f749e89cb14c2b7/src/compiler/watch.ts#L635

https://github.com/Microsoft/TypeScript/blob/67a6a9477f90d61955f92fb33e7b11491dbd17a5/src/compiler/program.ts#L165

Expected behavior:

TSC to work without 'crypto'

Actual behavior:

TSC fails without 'crypto'

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions