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

Can't use local workspace library in vite.config.ts - TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" #16040

Closed
7 tasks done
maximan3000 opened this issue Feb 27, 2024 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@maximan3000
Copy link

Describe the bug

Related to #13332

When i tried to setup local library with yarn workspaces, i've found out that this library doesn't work inside configuration file vite.config.ts - everything is fine until you try to start dev server - it throws error

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

Thats is problem, because i need shared configuration logic between projects in monorepo.

Actually, you still can use relative import for this library. For example, if you have local workspace library @foo/tools

// vite.config.ts

// throws error after starting dev server
import { defaultConfig } from '@foo/tools';

// works fine
import { defaultConfig } from './tools';

Reproduction

https://stackblitz.com/edit/vitejs-vite-lpsoay?file=main.js

Steps to reproduce

Just open the reproduction link - it automatically throws reported error (or start the dev server by yarn dev manually)

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.14.0 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.1.4 => 5.1.4

Used Package Manager

yarn

Logs

Click to expand!
failed to load config from /home/projects/vitejs-vite-lpsoay/vite.config.ts
error when starting dev server:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/projects/vitejs-vite-lpsoay/tools/index.ts
    at __node_internal_ (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:36:5406)
    at new <anonymous> (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:36:4168)
    at file: (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:150:1250)
    at defaultGetFormat (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:150:1573)
    at defaultLoad (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:254:833)
    at nextLoad (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:248:2120)
    at ESMLoader.load (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:248:5485)
    at ESMLoader.<anonymous> (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:248:8230)
    at new ModuleJob (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:181:767)
    at ESMLoader._createModuleJob2 (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:248:8151)
    at ESMLoader.getModuleJob (https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:248:4644)
    at async https://vitejsvitelpsoay-wusl.w-credentialless.staticblitz.com/blitz.6f234770.js:181:966
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Validations

Copy link

stackblitz bot commented Feb 27, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red
Copy link
Member

Duplicate of #5370

@sapphi-red sapphi-red marked this as a duplicate of #5370 Feb 27, 2024
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Feb 27, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants