From b2427fda47e2ddc4812e0716a3fc2cf68aa91b8f Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 19 Aug 2024 09:22:25 -0600 Subject: [PATCH] fix: use file url to import tsx at runtime --- src/config/ts-path.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/config/ts-path.ts b/src/config/ts-path.ts index 17a7b3ab..317443f0 100644 --- a/src/config/ts-path.ts +++ b/src/config/ts-path.ts @@ -1,5 +1,6 @@ import {access} from 'node:fs/promises' import {join, relative as pathRelative, sep} from 'node:path' +import {pathToFileURL} from 'node:url' import * as TSNode from 'ts-node' import Cache from '../cache' @@ -85,11 +86,14 @@ async function registerTsx(root: string, moduleType: 'commonjs' | 'module' | und if (!tsxPath) return debug('registering tsx at', root) debug('tsx path:', tsxPath) - const {register} = await import(tsxPath) + const {href} = pathToFileURL(tsxPath) + debug('tsx href:', href) + const {register} = await import(href) register() REGISTERED.add(root) - } catch { + } catch (error) { debug(`Could not find tsx. Skipping tsx registration for ${root}.`) + debug(error) } } @@ -104,8 +108,9 @@ async function registerTSNode(root: string, tsconfig: TSConfig): Promise { try { tsNode = require(tsNodePath) - } catch { + } catch (error) { debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`) + debug(error) memoizedWarn( `Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`, )