diff --git a/doc/api/errors.md b/doc/api/errors.md
index 0298c2b1e22163..171fc1254091dd 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -717,6 +717,17 @@ Data passed to a Brotli stream was not successfully compressed.
An invalid parameter key was passed during construction of a Brotli stream.
+
+
+### `ERR_NO_TYPESCRIPT`
+
+
+
+An attempt was made to use features that require [Native TypeScript support][], but Node.js was not
+compiled with TypeScript support.
+
### `ERR_BUFFER_CONTEXT_NOT_AVAILABLE`
@@ -4111,6 +4122,7 @@ An error occurred trying to allocate memory. This should never happen.
[ICU]: intl.md#internationalization-support
[JSON Web Key Elliptic Curve Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve
[JSON Web Key Types Registry]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-types
+[Native TypeScript support]: typescript.md#type-stripping
[Node.js error codes]: #nodejs-error-codes
[Permission Model]: permissions.md#permission-model
[RFC 7230 Section 3]: https://tools.ietf.org/html/rfc7230#section-3
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index e1228176a2d101..61c24febcb7e33 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -1600,6 +1600,8 @@ E('ERR_NO_CRYPTO',
'Node.js is not compiled with OpenSSL crypto support', Error);
E('ERR_NO_ICU',
'%s is not supported on Node.js compiled without ICU', TypeError);
+E('ERR_NO_TYPESCRIPT',
+ 'Node.js is not compiled with TypeScript support', Error);
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error, TypeError);
E('ERR_OUT_OF_RANGE',
(str, range, input, replaceDefaultBoolean = false) => {
diff --git a/lib/internal/modules/helpers.js b/lib/internal/modules/helpers.js
index feec9f4957e7ab..15483f4df294f8 100644
--- a/lib/internal/modules/helpers.js
+++ b/lib/internal/modules/helpers.js
@@ -27,7 +27,7 @@ const assert = require('internal/assert');
const { Buffer } = require('buffer');
const { getOptionValue } = require('internal/options');
-const { setOwnProperty, getLazy } = require('internal/util');
+const { assertTypeScript, setOwnProperty, getLazy } = require('internal/util');
const { inspect } = require('internal/util/inspect');
const lazyTmpdir = getLazy(() => require('os').tmpdir());
@@ -342,6 +342,7 @@ function loadTypeScriptParser(parser) {
if (parser) {
typeScriptParser = parser;
} else {
+ assertTypeScript();
const amaro = require('internal/deps/amaro/dist/index');
// Default option for Amaro is to perform Type Stripping only.
typeScriptParsingMode = getOptionValue('--experimental-transform-types') ? 'transform' : 'strip-only';
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 65ebef3f4f3e4c..9576dd6750b690 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -45,6 +45,7 @@ const {
const {
codes: {
ERR_NO_CRYPTO,
+ ERR_NO_TYPESCRIPT,
ERR_UNKNOWN_SIGNAL,
},
isErrorStackTraceLimitWritable,
@@ -65,6 +66,7 @@ const { getOptionValue } = require('internal/options');
const { encodings } = internalBinding('string_decoder');
const noCrypto = !process.versions.openssl;
+const noTypeScript = !process.versions.amaro;
const isWindows = process.platform === 'win32';
const isMacOS = process.platform === 'darwin';
@@ -194,6 +196,12 @@ function assertCrypto() {
throw new ERR_NO_CRYPTO();
}
+function assertTypeScript() {
+ if (noTypeScript)
+ throw new ERR_NO_TYPESCRIPT();
+}
+
+
/**
* Move the "slow cases" to a separate function to make sure this function gets
* inlined properly. That prioritizes the common case.
@@ -861,6 +869,7 @@ for (let i = 0; i < encodings.length; ++i)
module.exports = {
getLazy,
assertCrypto,
+ assertTypeScript,
cachedResult,
convertToValidSignal,
createClassWrapper,