Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 04fcd77

Browse files
fix: only require fast-text-encoding when needed (#740)
1 parent 326ba7f commit 04fcd77

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/crypto/browser/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as base64js from 'base64-js';
2222
// Not all browsers support `TextEncoder`. The following `require` will
2323
// provide a fast UTF8-only replacement for those browsers that don't support
2424
// text encoding natively.
25-
if (typeof TextEncoder === 'undefined') {
25+
if (typeof process === 'undefined' && typeof TextEncoder === 'undefined') {
2626
require('fast-text-encoding');
2727
}
2828

test/test.crypto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ describe('Node.js crypto tests', () => {
7373
const encodedString = crypto.encodeBase64StringUtf8(originalString);
7474
assert.strictEqual(encodedString, base64String);
7575
});
76+
77+
it('should not load fast-text-encoding while running in nodejs', () => {
78+
const loadedModules = Object.keys(require('module')._cache);
79+
const hits = loadedModules.filter(x => x.includes('fast-text-encoding'));
80+
assert.strictEqual(hits.length, 0);
81+
});
7682
});

0 commit comments

Comments
 (0)