sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.27k stars 250 forks source link

Issue: not-to-unresolvable return error when using typescript alias in module project #909

Closed throrin19 closed 8 months ago

throrin19 commented 8 months ago

Expected Behavior

Hello, I migrate all my project from CJS/ESM mix to pure ESM (very messy js ecosystem). Normally all my defined rules before migration should work correctly.

Current Behavior

After that I have several errors for specific imports using TS aliases. For all this aliases, I don't use extension, it's a one:one link (I think the problem is here)

Possible Solution

I don't know, specific settings to set for this aliases, no extension is needed and read correctly alias target

Steps to Reproduce (for bugs)

In my case, I have this tsConfig:

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "compilerOptions": {
    "baseUrl": "./",
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": false,
    "sourceMap": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "composite": true,
    "useDefineForClassFields": false,
    "noImplicitAny": false,
    "strict": true,
    "target": "ES2022",
    "moduleResolution": "NodeNext",
    "module": "NodeNext",
    "lib": [
      "esnext",
      "dom",
      "DOM.Iterable"
    ],
    "types": [
      "node",
      "vuetify"
    ],
    "paths": {
      "@module/alerts": ["src/modules/alerts/index.js"],
      "@module/companies": ["src/modules/companies/index.js"],
      "@module/customers": ["src/modules/customers/index.js"],
      "@module/datapushers": ["src/modules/datapushers/index.js"],
      "@module/events": ["src/modules/events/index.js"],
      "@module/externalConnectors": ["src/modules/externalConnectors/index.js"],
      "@module/factories": ["src/modules/factories/index.js"],
      "@module/homes": ["src/modules/homes/index.js"],
      "@module/importCsv": ["src/modules/importCsv/index.js"],
      "@module/infrastructure": ["src/modules/infrastructure/index.js"],
      "@module/login": ["src/modules/login/index.js"],
      "@module/m2m": ["src/modules/m2m/index.js"],
      "@module/profile": ["src/modules/profile/index.js"],
      "@module/users": ["src/modules/users/index.js"],
      "@/assets/*": ["./src/assets/*"],
      "@/components/*": ["./src/components/*"],
      "@/langs/*": ["./src/langs/*"],
      "@/libs/*": ["./src/libs/*"],
      "@/pages/*": ["./src/pages/*"],
      "@/plugins/*": ["./src/plugins/*"],
      "@/router/*": ["./src/router/*"],
      "@/stores/*": ["./src/stores/*"],
      "@/styles/*": ["./src/styles/*"],
      "@/types/*": ["./src/types/*"],
      "@/use/*": ["./src/use/*"],
      "@/configs": ["./src/configs.js"],
      "@/modules": ["./src/modules.js"],
      "@/router": ["./src/router.js"]
    }
  },
  "include": [
    "env.d.ts",
    "./src/**/*.ts",
    "./src/**/*.d.ts",
    "./src/**/*.tsx",
    "./src/**/*.vue",
    "./src/**/*.json",
    "vite.config.ts",
    "package.json"
  ]
}

All works fine for compilation part. But I have all this errors after depcheck :

  error not-to-unresolvable: src/use/responsive.ts → @/configs
  error not-to-unresolvable: src/router/customer.ts → @/modules
  error not-to-unresolvable: src/router/company.ts → @/modules
  error not-to-unresolvable: src/router/admin.ts → @/modules
  error not-to-unresolvable: src/router.ts → @/modules
  error not-to-unresolvable: src/plugins/vuetify.ts → @/configs
  error not-to-unresolvable: src/plugins/i18n.ts → @/configs
  error not-to-unresolvable: src/pages/CustomerRoot.vue → @/router
  error not-to-unresolvable: src/pages/CompanyRoot.vue → @/router
  error not-to-unresolvable: src/pages/AdminRoot.vue → @/router
  error not-to-unresolvable: src/modules/users/pages/UsersHome.vue → @module/customers
  error not-to-unresolvable: src/modules/users/pages/UsersHome.vue → @module/companies
  error not-to-unresolvable: src/modules/users/pages/UserForm.vue → @module/customers
  error not-to-unresolvable: src/modules/users/pages/BaseRightsForm.vue → @module/customers
  error not-to-unresolvable: src/modules/users/components/UsersSearch.vue → @module/customers
  error not-to-unresolvable: src/modules/users/components/UsersSearch.vue → @module/companies
  error not-to-unresolvable: src/modules/users/components/CustomersAccess.vue → @module/customers
  error not-to-unresolvable: src/modules/users/components/CompaniesAccess.vue → @module/factories
  error not-to-unresolvable: src/modules/users/components/CompaniesAccess.vue → @module/companies
  error not-to-unresolvable: src/modules/profile/pages/ProfilePage.vue → @/configs
  error not-to-unresolvable: src/modules/infrastructure/pages/RoutesForm.vue → @module/factories
  error not-to-unresolvable: src/modules/infrastructure/pages/RoutesForm.vue → @module/customers
  error not-to-unresolvable: src/modules/infrastructure/pages/ApiKeyForm.vue → @module/customers
  error not-to-unresolvable: src/modules/infrastructure/pages/ApiKeyForm.vue → @module/companies
  error not-to-unresolvable: src/modules/infrastructure/components/RoutesSearch.vue → @module/factories
  error not-to-unresolvable: src/modules/infrastructure/components/RoutesSearch.vue → @module/customers
  error not-to-unresolvable: src/modules/factories/pages/Measures/MeasureFormEdit.vue → @module/infrastructure
  error not-to-unresolvable: src/modules/factories/pages/Measures/MeasureFormAdd.vue → @module/infrastructure
  error not-to-unresolvable: src/modules/factories/pages/authTokens/AuthTokensHome.vue → @module/infrastructure
  error not-to-unresolvable: src/modules/factories/components/AqCppSelect/AqCppSelect.vue → @module/companies
  error not-to-unresolvable: src/modules/events/pages/EventForm.vue → @module/factories
  error not-to-unresolvable: src/modules/companies/pages/CompanyRightForm.vue → @module/users
  error not-to-unresolvable: src/modules/companies/pages/CompanyRightForm.vue → @module/factories
  error not-to-unresolvable: src/modules/companies/pages/CompanyForm.vue → @module/customers
  error not-to-unresolvable: src/modules/companies/components/CompaniesSearch.vue → @module/customers
  error not-to-unresolvable: src/modules.ts → @module/users
  error not-to-unresolvable: src/modules.ts → @module/profile
  error not-to-unresolvable: src/modules.ts → @module/m2m
  error not-to-unresolvable: src/modules.ts → @module/login
  error not-to-unresolvable: src/modules.ts → @module/infrastructure
  error not-to-unresolvable: src/modules.ts → @module/importCsv
  error not-to-unresolvable: src/modules.ts → @module/homes
  error not-to-unresolvable: src/modules.ts → @module/factories
  error not-to-unresolvable: src/modules.ts → @module/externalConnectors
  error not-to-unresolvable: src/modules.ts → @module/events
  error not-to-unresolvable: src/modules.ts → @module/datapushers
  error not-to-unresolvable: src/modules.ts → @module/companies
  error not-to-unresolvable: src/modules.ts → @module/alerts
  error not-to-unresolvable: src/main.ts → @/router
  error not-to-unresolvable: src/libs/request.ts → @/router
  error not-to-unresolvable: src/libs/request.ts → @/configs

Your Environment

sverweij commented 8 months ago

Hi @throrin19 thanks for raising this issue. It worried me a bit so I've attempted to create a minimal reprodution sample - see dependency-cruiser-repro-repo/909. The issue doesn't repeat there, however, which means there's a difference between the private repo and that one.

throrin19 commented 8 months ago

I found the problem. I made alias to .js file, no to the real .ts file and it works fine after change that.

Sorry for this mistake and thanks for your help :)