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

Unable to resolve path to module with aliases. #359

Closed
sebastien-comeau opened this issue Feb 18, 2025 · 14 comments · Fixed by #360
Closed

Unable to resolve path to module with aliases. #359

sebastien-comeau opened this issue Feb 18, 2025 · 14 comments · Fixed by #360

Comments

@sebastien-comeau
Copy link

Starting from tinyglobby@^0.2.11, eslint-import-resolver-typescript is unable to resolve module paths when using aliases. As a workaround, I had to override tinyglobby to version 0.2.10 to restore functionality.

This issue can be reproduced in my pull request DTS-STN/future-sir#226 with commit DTS-STN/future-sir@e1da254, where the problem occurs. The next commit DTS-STN/future-sir@f0e3ce2 includes the override, which resolves the issue.

Image

@carlocorradini
Copy link
Contributor

That's because tinyglobby is configured to avoid dot directories.
@JounQin @SukkaW Do you want to allow dot directories?
I don't know the implications in security/performance

@carlocorradini
Copy link
Contributor

carlocorradini commented Feb 18, 2025

Here

? globSync(tsconfigResult.config.include, {
and here
globSync(defaultInclude, {
we can add dot: true

@JounQin
Copy link
Collaborator

JounQin commented Feb 18, 2025

Does this means tinyglobby breaks in a patch version?

@carlocorradini
Copy link
Contributor

I don't know but I've seen the dot option also in version 0.2.10 if I'm not allucinated.
If it's there previously, it was silently ignored.
Tomorrow I'll push a PR with a test for both tsconfig and include property

@SuperchupuDev
Copy link

hi! tinyglobby author here. that's very odd. tinyglobby (in both 0.2.10 and 0.2.11) is configured by default to avoid dot directories, behavior shouldn't have changed between versions. so either 0.2.10 mistakenly didn't skip directories which should have been skipped or 0.2.11 somehow made dot matching (with the dot option disabled) stricter. if any of you can provide a reproducible example of results changing between the two versions i can take a closer look

@carlocorradini
Copy link
Contributor

@SuperchupuDev

  1. Clone https://github.com/carlocorradini/eslint-import-resolver-typescript
  2. cd eslint-import-resolver-typescript
  3. git checkout dot
  4. yarn --immutable
  5. yarn remove tinyglobby
  6. yarn add [email protected]
  7. Open src/index.ts and remove dot: true option from every call to globSync function
  8. yarn run-s build test

There are three new tests that look for dot directories.
Let's verify if they fail or pass, even though the dot: true option was deleted.

@chrisweb
Copy link

chrisweb commented Feb 19, 2025

As a workaround I downgraded to eslint-import-resolver-typescript 3.7.0

Does this means tinyglobby breaks in a patch version?

The latest version that supports aliases (for me) is eslint-import-resolver-typescript 3.7.0 (which was still using fast-glob), downgrading eslint-import-resolver-typescript from 3.8.2 to 3.8.0 was not enough

tinyglobby (in both 0.2.10 and 0.2.11) is configured by default to avoid dot directories

I downgraded my tinyglobby from 0.2.11 to v0.2.10 and it made no difference (both break aliases when not using the dot option)

@carlocorradini
Copy link
Contributor

@chrisweb See PR #360

It should be merged today and a new version will be released automatically

@SuperchupuDev
Copy link

great will check it out. meanwhile if you can manage to provide a minimal isolated example that only involves one glob call it'd be greatly appreciated 🙏

@SuperchupuDev
Copy link

@carlocorradini while the tests do fail with 0.2.11, i added a few asserts and installing 0.2.10 at the same time to make sure the result didn't change between versions, but i can't seem to find any assert failure

@SuperchupuDev
Copy link

SuperchupuDev commented Feb 19, 2025

I downgraded my tinyglobby from 0.2.11 to v0.2.10 and it made no difference (both break aliases when not using the dot option)

ah, so both versions have the issue. didn't realize. actually that makes my above findings have a lot more sense. i'm glad it's not a 0.2.11 regression at least? although it's really odd that this kind of test failure had gone unnoticed for so many months. if any of you can find a specific minimal repro where tinyglobby returns different results than fast-glob (as tinyglobby is meant to be a replacement to it) i can try making it consistent with fast-glob

@sebastien-comeau
Copy link
Author

The issue has been fixed in my project. Thanks again! :)

@befabry
Copy link

befabry commented Feb 23, 2025

Hello,

I noticed a regression from 3.7.0 to 3.8.2.

3.7.0


> [email protected] lint-fix
> eslint --fix "{src,apps,libs,test}/**/*.{ts,tsx,css}"

npm notice
npm notice New major version of npm available! 10.9.2 -> 11.1.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.1.0
npm notice To update run: npm install -g [email protected]
npm notice

However when I'm upgrading to 3.8.2

❯ dcr --rm frontend npm run lint-fix

> [email protected] lint-fix
> eslint --fix "{src,apps,libs,test}/**/*.{ts,tsx,css}"


/app/src/components/ui/button.tsx
  4:33  error  Unable to resolve path to module '@/lib/utils'  import-x/no-unresolved

/app/src/components/ui/form.tsx
  14:33  error  Unable to resolve path to module '@/lib/utils'  import-x/no-unresolved

/app/src/components/ui/input.tsx
  2:33  error  Unable to resolve path to module '@/lib/utils'  import-x/no-unresolved

/app/src/components/ui/label.tsx
  3:33  error  Unable to resolve path to module '@/lib/utils'  import-x/no-unresolved

/app/src/pages/AddItem/index.tsx
  4:112  error  Unable to resolve path to module '@/components/ui'  import-x/no-unresolved
  5:85   error  Unable to resolve path to module '@/helpers'        import-x/no-unresolved
  6:26   error  Unable to resolve path to module '@/hooks'          import-x/no-unresolved
  7:35   error  Unable to resolve path to module '@/messages'       import-x/no-unresolved
  8:27   error  Unable to resolve path to module '@/responses'      import-x/no-unresolved

... other errors

I haven't changed my config, but it doesn't seem to resolve the aliased paths. Here's (part of) my eslint config

// @ts-check
import eslint from '@eslint/js';
import * as tsParser from '@typescript-eslint/parser';
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript';
import eslintPluginImportX from 'eslint-plugin-import-x';
import jsxA11y from 'eslint-plugin-jsx-a11y'
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import unusedImports from 'eslint-plugin-unused-imports';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint, { configs as tsconfigs } from 'typescript-eslint';

export default tseslint.config(
  {
    ignores: ['eslint.config.mjs'],
  },
  eslint.configs.recommended,
  ...tsconfigs.recommendedTypeChecked,
  react.configs.flat.recommended,
  jsxA11y.flatConfigs.recommended,
  eslintPluginImportX.flatConfigs.recommended,
  eslintPluginImportX.flatConfigs.typescript,
  eslintPluginPrettierRecommended,
  {
    plugins: {
      // react,
      //@ts-expect-error: https://github.com/facebook/react/issues/30119
      'react-hooks': reactHooks,
      'react-refresh': reactRefresh,
      'unused-imports': unusedImports,
    },

    languageOptions: {
      globals: {
        ...globals.browser,
      },

      parser: tsParser,
      ecmaVersion: 'latest',
      sourceType: 'module',

      parserOptions: {
        project: ['tsconfig.json', 'tsconfig.app.json', 'tsconfig.node.json'],
        tsconfigRootDir: import.meta.dirname,
        ecmaFeatures: {
          jsx: true,
        },
      },
    },

    settings: {
      // https://www.npmjs.com/package/eslint-import-resolver-typescript#configuration
      'import/resolver-next': [
        createTypeScriptImportResolver({
          alwaysTryTypes: true,
          project: ['<root>/tsconfig.json', '<root>/tsconfig.app.json', '<root>/tsconfig.node.json'],
          extensions: ['.js', '.jsx', '.ts', '.tsx'],
        }),
      ],

      'import-x/ignore': [
        '\.(scss|less|css)$'
      ],

      react: {
        version: 'detect',
      },
    },

    rules: {

      // Style imports :

      // https://typescript-eslint.io/blog/consistent-type-imports-and-exports-why-and-how/
      // Consistently add inline `type` to imports & exports
      '@typescript-eslint/consistent-type-exports': ['error', { fixMixedExportsWithInlineTypeSpecifier: true }],
      '@typescript-eslint/consistent-type-imports': 'error',
      'import-x/consistent-type-specifier-style': ['error', 'prefer-inline'],
      'import-x/no-duplicates': ['error', { 'prefer-inline': true }],

      // Alphabetical order imports
      'import-x/order': [
        'error',
        {
          groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],

          pathGroups: [
            {
              pattern: '@/**',
              group: 'internal',
            },
          ],

          alphabetize: {
            order: 'asc',
            caseInsensitive: true,
          },
        },
      ],
      'sort-imports': [
        'error',
        {
          ignoreCase: true,
          ignoreDeclarationSort: true,
        },
      ],

      // Find and remove unused es6 module imports
      'unused-imports/no-unused-imports': 'error',
    },
  },
);

Is there something I can do to fix it ? I temporarily downgraded

@carlocorradini
Copy link
Contributor

@befabry Retry with version 3.8.3.
If it does not work please create a repro

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

Successfully merging a pull request may close this issue.

6 participants