Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite.config.ts isn't transpiled when used with ts-node #9112

Closed
7 tasks done
sodatea opened this issue Jul 14, 2022 · 0 comments · Fixed by #9118
Closed
7 tasks done

vite.config.ts isn't transpiled when used with ts-node #9112

sodatea opened this issue Jul 14, 2022 · 0 comments · Fixed by #9118
Labels
p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release

Comments

@sodatea
Copy link
Member

sodatea commented Jul 14, 2022

Describe the bug

When using Vite with ts-node (Cypress does so), the vite.config.ts isn't transpiled, and is parsed directly by ts-node.

Therefore, if the project doesn't have "type": "module" configured (most old projects don't), and uses import.meta.url in the config file (create-vue recommends configuring alias using import.meta.url), a SyntaxError would be thrown when parsing the config file.

It is a regression introduced in #8556

Reproduction

Source code: https://github.com/sodatea/vite-ts-node
Online playground: https://replit.com/@sodatea/vite-ts-node

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 79.00 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/Library/Caches/fnm_multishells/3199_1657785143937/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/3199_1657785143937/bin/yarn
    npm: 8.12.2 - ~/Library/Caches/fnm_multishells/3199_1657785143937/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 100.0.2
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-vue: ^3.0.0 => 3.0.0
    vite: ^3.0.0 => 3.0.0

Used Package Manager

pnpm

Logs

$ pnpm dev

> vite-ts-node@0.0.0 dev /Users/haoqun/Reproductions/vite-ts-node
> ts-node ./node_modules/vite/bin/vite.js

failed to load config from /Users/haoqun/Reproductions/vite-ts-node/vite.config.ts
error when starting dev server:
/Users/haoqun/Reproductions/vite-ts-node/vite.config.ts:1
import { fileURLToPath } from 'url';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Module.m._compile (/Users/haoqun/Reproductions/vite-ts-node/node_modules/.pnpm/ts-node@10.9.1_2zqz24ol5yhbv2blv4fh7akzrq/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/haoqun/Reproductions/vite-ts-node/node_modules/.pnpm/ts-node@10.9.1_2zqz24ol5yhbv2blv4fh7akzrq/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
 ELIFECYCLE  Command failed with exit code 1.

Validations

@sodatea sodatea added pending triage bug p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Jul 14, 2022
@sapphi-red sapphi-red added the regression The issue only appears after a new release label Jul 14, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants