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

baseUrl not working in Nest 10 with swc #11937

Closed
2 tasks done
KirianCaumes opened this issue Jun 29, 2023 · 1 comment
Closed
2 tasks done

baseUrl not working in Nest 10 with swc #11937

KirianCaumes opened this issue Jun 29, 2023 · 1 comment
Labels
needs triage This issue has not been looked into type: bug 😭

Comments

@KirianCaumes
Copy link

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

No response

NestJS version

9.5.0 -> 10.0.5

Describe the regression

When I run npm run start (nest start) in my project with NestJs 10 and swc enabled, an error is thrown:

> test-nestjs@0.0.1 start
> nest start

✔  TSC  Initializing type checker...
>  TSC  Found 0 issues.
>  SWC  Running...
Successfully compiled: 5 files with swc (26.57ms)
Error: Cannot find module 'app.module'
Require stack:
- /home/kirian/Projects/Perso/test-nestjs/dist/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Function.Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/kirian/Projects/Perso/test-nestjs/dist/main.js:6:20)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

It seems that the baseUrl option from my tsconfig.json and .swcrc is not recognized when using non-relative import.

Minimum reproduction code

https://github.com/KirianCaumes/nestjs-bug-swc-import

Input code

// src/main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from 'app.module'; // 👈

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(5002);
}
bootstrap();
// nest-cli.json
{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "builder": "swc",
    "typeCheck": true
  }
}
// .swcrc
{
    "$schema": "https://json.schemastore.org/swcrc",
    "sourceMaps": true,
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "decorators": true,
            "dynamicImport": true
        },
        "baseUrl": "./src"
    },
    "minify": false
}
// tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}

Expected behavior

It should work the same way as without swc enabled and with baseUrl being used.

Other

No response

@KirianCaumes KirianCaumes added needs triage This issue has not been looked into type: bug 😭 labels Jun 29, 2023
@kamilmysliwiec
Copy link
Member

Please, report this issue in the swc https://github.com/swc-project/swc repository

@nestjs nestjs locked and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into type: bug 😭
Projects
None yet
Development

No branches or pull requests

2 participants