From 77ba1e242c5f7c4d27e1e3e75dca19582fbbc223 Mon Sep 17 00:00:00 2001 From: Dave Honneffer Date: Mon, 26 Jun 2023 09:14:00 +0200 Subject: [PATCH] fix: throw better errors for users who are missing 'fetch' (#132) --- src/plugin.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/plugin.js b/src/plugin.js index 17de4f5..ada85e1 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -16,6 +16,7 @@ import { postprocess } from '#postprocess'; // TODO: improve generic type passed here /** @type {import('@unocss/core').Preset} */ export function presetWarp (options = {}) { + checkEnvironment(); const externalizeClasses = options.externalizeClasses; const externalClasses = options.externalClasses ?? []; // will possibly be our own list in the future const theme = useTheme(options); @@ -30,4 +31,14 @@ export function presetWarp (options = {}) { }; } +function checkEnvironment() { + if (typeof fetch === 'undefined') { + if (typeof process !== 'undefined') { + const NODE_MAJOR_VERSION = process.versions.node.split('.')[0]; + if (NODE_MAJOR_VERSION < 18) throw new Error('Warp requires node 18 or higher'); + } + throw new Error("'fetch' is undefined for some reason and presetWarp requires it"); + } +} + export default presetWarp;