jiti icon indicating copy to clipboard operation
jiti copied to clipboard

Error when loading a `vite.config.ts` file with the `sveltekit` plugin.

Open thenbe opened this issue 2 years ago • 1 comments

jiti fails to load a vite.config.ts file, when that file calls the sveltekit plugin. (like the one that comes with the sveltekit demo app)

Error

[jiti] [transpile] [esm] /home/nbe/projects/playground/repro-jiti-sveltekit/ts.js (4.032ms)
/home/nbe/projects/playground/repro-jiti-sveltekit/ts.js:5
  exports.ts = ts = (await Promise.resolve().then(() => require('typescript'))).default;

SyntaxError: Unexpected identifier 'Promise'

Reproduction

Here is a minimal reproduction which includes only the single file from the sveltekit repo that jiti errors on. The steps are in the readme.

Questions

  1. Is my understanding correct in that we ideally want to instruct jiti to avoid transforming this file, as it is "already ESM"?
  2. Is it fair to assume that closing #72 will also fix this issue?
  3. Are there any other alternatives I could try to work around this in the meantime?

Context

I was taking a stab at fixing a knip issue which is currently blocked by this error.

Environment

Environment

  System:
    OS: Linux 6.1 NixOS 24.05 (Uakari) 24.05 (Uakari)
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i9-12900K
    Memory: 20.28 GB / 31.13 GB
    Container: Yes
    Shell: 5.9 - /run/current-system/sw/bin/zsh
  Binaries:
    Node: 20.10.0 - /etc/profiles/per-user/nbe/bin/node
    npm: 10.2.3 - /etc/profiles/per-user/nbe/bin/npm
    pnpm: 8.10.5 - /etc/profiles/per-user/nbe/bin/pnpm

thenbe avatar Dec 16 '23 19:12 thenbe

I just realized that I forgot to link to the minimal repro 🤦🏼‍♂️

https://github.com/thenbe/repro-jiti-sveltekit

thenbe avatar Mar 14 '24 09:03 thenbe

With jiti v2, we have adopted native-ESM support and top level imports supported out of the box for main jiti CLI.

pi0 avatar Sep 25 '24 14:09 pi0