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

Imported TypeScript files in eslint.config.ts doesn't work #95

Open
ferferga opened this issue Oct 14, 2024 · 5 comments
Open

Imported TypeScript files in eslint.config.ts doesn't work #95

ferferga opened this issue Oct 14, 2024 · 5 comments

Comments

@ferferga
Copy link

The following structure is publicily available at https://github.com/jellyfin/jellyfin-vue

Steps to reproduce

  1. Click on Code > Create codespace from master (or clone the repository locally)
  2. cd frontend && npm run lint:inspect

Description

This an overview of the setup

  • Using TypeScript configuration files with jiti v2. Looks like that is already covered
  • A monorepo (called @jellyfin-vue/configs in my case) where TypeScript modules export factory functions for rule configs.
  • Those factory functions are imported in frontend/eslint.config.ts, working perfectly with ESLint but not with the inspector.
@voxpelli
Copy link
Contributor

I have a hard time understanding what it is that doesn’t work.

Can you maybe add a screenshot or something where you show what’s wrong or missing?

@ferferga
Copy link
Author

@voxpelli I was able to better triage the issue and create a minimal reproduction: https://stackblitz.com/edit/vitejs-vite-9abzaz

Steps to reproduce

  1. cd packages/configs and run npm run lint:inspect
  2. ESLint config inspector will load successfully, since the TypeScript file imported is referenced from the same project
  3. Change to the packages/main directory and run npm run lint:inspect there. The config inspector will fail to load with the following error, since the base rules are being imported from the monorepo:
    Image

Additional context

It looks like the issue exists when importing .ts files from node_modules in monorepo setups. Similar to what happens in Vite. Hence, the workarounds listed there are also applicable to this project

@KryziK
Copy link

KryziK commented Feb 7, 2025

I'm running into this same issue. I have two projects:

  • An ESLint Shared Config project which directly exports .ts files instead of transpiling
  • A consuming project whose eslint.config.ts simply re-exports the config from the above project

Running eslint (with any of --fix, --debug, --print-config) works just fine, but specifically only the inspector fails with:

ℹ Reading ESLint config from C:\project2\eslint.config.ts
Failed to load `eslint.config.js`.
Note that `@eslint/config-inspector` only works with the flat config format:
https://eslint.org/docs/latest/use/configure/configuration-files-new
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\project2\node_modules\project1\src\index.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:218:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:244:36)
    at defaultLoad (node:internal/modules/esm/load:122:22)
    at async ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:483:32) {

I am not well-versed enough in js/ts/frontend to understand what I can do to work around this issue.

@antfu
Copy link
Collaborator

antfu commented Feb 8, 2025

I don't think it's a good practice to ship .ts directly to npm, at least not until Node v23+, which ships the strip-types feature by default. I consider this as an expected behaviour as this is out-of-scope for jiti to handle files inside node_modules

@KryziK
Copy link

KryziK commented Feb 8, 2025

In my case, these are private, scoped packages that my team uses internally via Azure Artifacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants