I'm developing a Nest.js app and I want to use the SWC for the first time. I followed the Nest.js docs instructions (+), but I've got an error.
I'm using Prisma in my project and I've created a folder prisma
in the root directory, with the same level as src
.
The folder structure is like this:
ROOT DIRECTORY STRUCTURE:
.
├── prisma
│ ├── migrations
│ ├── prisma.service.ts
│ └── schema.prisma
├── src
│ ├── common
│ ├── config
│ ├── modules
│ ├── types
│ ├── app.module.ts
│ ├── main.ts
│ ├── metadata.ts
│ └── schema.gpl
├── bun.lockb
├── nest-cli.json
├── package.json
├── README.md
├── tsconfig.build.json
└── tsconfig.json
I want the folder structure of dist
to be the same as the root directory after compilation with SWC (i.e. the prisma
and src
are both compiled and on the same level) but I'm getting this:
DIST DIRECTORY STRUCTURE:
.
├── common
│ └── decorators
├── config
│ ├── environment.config.js
│ ├── environment.config.js.map
│ ├── index.js
│ └── index.js.map
├── modules
│ ├── auth
│ ├── comments
│ ├── posts
│ └── users
├── app.module.js
├── app.module.js.map
├── main.js
├── main.js.map
├── metadata.js
├── metadata.js.map
└── tsconfig.build.tsbuildinfo
Only the src
is compiled and is all I can find in dist
.
Here's the tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
Here's the .swcrc
:
{
"$schema": "https://json.schemastore.org/swcrc",
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"baseUrl": "./"
},
"minify": false
}
Here's the script I use to run the project with:
scripts: {
"start:swc": "dotenv -e .dev.env -- nest start -b swc -w --type-check",
}
Since prisma
directory is not compiled, the runtime can't import anything from it inside src
, and hence the error:
When I run the project without SWC, everything works OK.
I've tried this answer, and it fixed the starting path of import (prisma/
to ../../../prisma/
).
Why isn't SWC compiling the prisma
folder?
Runtime and tools:
- Bun -
1.0.7
- Nest.js -
10.0.0
@swc/cli
-0.1.63
@swc/core
-1.3.96
For SWC to compile the prisma folder, you need to compile such folder explicitly after the nest build:
nest build && swc prisma --out-dir dist