nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.73k stars 7.63k forks source link

SWC breaks path aliases #11863

Closed dgastudio closed 1 year ago

dgastudio commented 1 year ago

Is there an existing issue for this?

Current behavior

SWC Running... Successfully compiled: 341 files with swc (124.35ms) Watching for file changes. Error: Cannot find module '@system/account/account.module'

Minimum reproduction code

it can't be reproduces as it's related to builder

Steps to reproduce

nestjs-cli.json

{ "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "builder": "swc", "assets": [ { "include": "i18n/*/", "watchAssets": true } ] } }

tsconfig.ts { "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "es2017", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "incremental": true, "skipLibCheck": true, "strictNullChecks": false, "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "paths": { "@modules/": [ "src/modules/" ], "@system/": [ "src/system/" ] }, "watchFile": "dynamicPriorityPolling", "watchDirectory": "dynamicPriorityPolling", "excludeDirectories": [ "**/node_modules", "dist" ] } }

Expected behavior

it should be compiled

Package

Other package

No response

NestJS version

10

Packages versions

{
  "name": "HKeeper",
  "version": "3.0.0",
  "description": "",
  "author": "hkeeper.team",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "typeorm": "env-cmd ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
    "migration:generate": "npm run typeorm -- --dataSource=src/_db/data-source.ts migration:generate",
    "migration:create": "npm run typeorm -- migration:create",
    "migration:run": "npm run typeorm -- --dataSource=src/_db/data-source.ts migration:run",
    "migration:revert": "npm run typeorm -- --dataSource=src/_db/data-source.ts migration:revert",
    "schema:drop": "npm run typeorm -- --dataSource=src/_db/data-source.ts schema:drop",
    "seed:create": "hygen seeds create",
    "seed:run": "ts-node -r tsconfig-paths/register ./src/_db/seeds/run-seed.ts",
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "env-cmd jest --config ./test/jest-e2e.json",
    "deploy": "npm install && npm run build && npm run start:dev"
  },
  "dependencies": {
    "@aws-sdk/client-lambda": "^3.356.0",
    "@aws-sdk/client-s3": "3.354.0",
    "@fastify/compress": "^6.4.0",
    "@fastify/cookie": "^8.3.0",
    "@fastify/formbody": "^7.4.0",
    "@fastify/helmet": "^10.1.1",
    "@fastify/static": "^6.10.2",
    "@google-cloud/translate": "^7.2.1",
    "@nestjs-modules/mailer": "1.8.1",
    "@nestjs/axios": "^3.0.0",
    "@nestjs/cache-manager": "^2.0.0",
    "@nestjs/common": "10.0.3",
    "@nestjs/config": "3.0.0",
    "@nestjs/core": "10.0.3",
    "@nestjs/event-emitter": "^2.0.0",
    "@nestjs/jwt": "10.1.0",
    "@nestjs/mapped-types": "2.0.1",
    "@nestjs/passport": "10.0.0",
    "@nestjs/platform-express": "10.0.3",
    "@nestjs/platform-fastify": "^10.0.3",
    "@nestjs/schedule": "^3.0.1",
    "@nestjs/swagger": "7.0.3",
    "@nestjs/terminus": "^10.0.1",
    "@nestjs/typeorm": "10.0.0",
    "@sentry/node": "^7.56.0",
    "@sjnprjl/nestjs-stripe": "^1.0.3",
    "@swc/cli": "^0.1.62",
    "@swc/core": "^1.3.66",
    "@types/amqplib": "^0.10.1",
    "@types/bcrypt": "^5.0.0",
    "@types/cookie-parser": "^1.4.3",
    "@types/cron": "^2.0.1",
    "@types/lodash": "^4.14.195",
    "@types/multer-s3": "^3.0.0",
    "@types/qrcode": "^1.5.0",
    "@types/uuid": "^9.0.2",
    "@willsoto/nestjs-prometheus": "^5.2.0",
    "amqplib": "^0.10.3",
    "aws-sdk": "^2.1401.0",
    "axios": "^1.4.0",
    "bcrypt": "^5.1.0",
    "bcryptjs": "^2.4.3",
    "class-transformer": "0.5.1",
    "class-validator": "0.14.0",
    "compression": "^1.7.4",
    "cookie-parser": "^1.4.6",
    "dayjs": "^1.11.8",
    "group-items": "^2.2.1",
    "lodash": "^4.17.21",
    "multer": "1.4.5-lts.1",
    "multer-s3": "3.0.1",
    "nestjs-cls": "^3.5.0",
    "nestjs-i18n": "^10.2.6",
    "nodemailer": "6.9.3",
    "npm-check-updates": "^16.10.12",
    "passport": "0.6.0",
    "passport-anonymous": "1.0.1",
    "passport-jwt": "4.0.1",
    "pg": "^8.11.0",
    "prom-client": "^14.2.0",
    "qrcode": "^1.5.3",
    "reflect-metadata": "0.1.13",
    "rimraf": "^5.0.1",
    "rrule": "^2.7.2",
    "rxjs": "7.8.1",
    "source-map-support": "0.5.21",
    "stripe": "^12.9.0",
    "swagger-stats": "^0.99.7",
    "typeorm": "0.3.17",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.3",
    "@nestjs/schematics": "10.0.1",
    "@nestjs/testing": "10.0.3",
    "@types/bcryptjs": "2.4.2",
    "@types/express": "4.17.17",
    "@types/facebook-js-sdk": "3.3.6",
    "@types/jest": "29.5.2",
    "@types/multer": "1.4.7",
    "@types/node": "20.3.1",
    "@types/passport-anonymous": "1.0.3",
    "@types/passport-jwt": "3.0.8",
    "@types/supertest": "2.0.12",
    "@types/twitter": "1.7.1",
    "@typescript-eslint/eslint-plugin": "5.60.0",
    "@typescript-eslint/parser": "5.60.0",
    "env-cmd": "10.1.0",
    "hygen": "6.2.11",
    "ts-loader": "9.4.3",
    "ts-node": "10.9.1",
    "tsconfig-paths": "4.2.0",
    "tslib": "2.5.3",
    "typescript": "5.1.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  },
  "engines": {
    "node": ">=16.0.0"
  }
}

Node.js version

20+

In which operating systems have you tested?

Other

No response

dgastudio commented 1 year ago

i can confirm that installing @swc/cli @swc/core breaks the aliases

jmcdo29 commented 1 year ago

SWC uses the .swcrc for path aliases. You need to define them in both the swcrc file for swc and the tsconfig.json for your IDE. Ideally, there would be some kind of script that merges these, but for now you can at least know that fact

dgastudio commented 1 year ago

thank you @jmcdo29 seems no issues with missing modules now, but there are a lot of other errors Cannot access '*' before initialization

i think i'll wait a little bit, before this new feature becomes more estable

kamilmysliwiec commented 1 year ago

This feature is already stable.

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.