I’m working on a project where I like to keep unit tests along with use cases and e2e tests along with controllers, all within the `src/` folder. However, I’m facing an issue with the build script:
```json
“build:prod”: “tsup src --out-dir build”,
```
This script is compiling my `*.spec.ts` files, and when deploying, I get the following error:
✘ [ERROR] Could not resolve “vitest”
This happens because my spec files import `vitest` and `supertest`, which are development dependencies.
To try to resolve this, I created a script called remove-spec-files.ts:
```javascript
import fs from ‘node:fs’
import path from ‘node:path’
function deleteSpecFiles(dirPath: string): void {
const files = fs.readdirSync(dirPath)
for (const file of files) {
const filePath = path.join(dirPath, file)
const stat = fs.lstatSync(filePath)
if (stat.isDirectory()) {
deleteSpecFiles(filePath)
} else if (filePath.endsWith('.spec.js')) {
fs.unlinkSync(filePath)
}
}
}
const isProduction = process.env.NODE_ENV === ‘production’
const buildPath = isProduction
? process.cwd()
: path.join(process.cwd(), ‘build’)
deleteSpecFiles(buildPath)
```
After compiling, this script is placed at the root of the build folder and is executed with the following script:
```json
“build:prod:remove-spec-files”: “node remove-spec-files.js”,
```
In Render, I call both scripts like this:
```bash
npm install && npx prisma migrate deploy && npm run build:prod && npm run build:prod:remove-spec-files
```
Even so, I continue to receive the error during deployment:
```
CLI Using tsconfig: tsconfig.json
May 3 10:40:39 AM CLI tsup v6.7.0
May 3 10:40:39 AM CLI Target: es2020
May 3 10:40:39 AM CJS Build start
May 3 10:40:39 AM ✘ [ERROR] Could not resolve “vitest”
```
I would like to ask for help in solving this problem and removing spec files from my `src` folder during the tsup compilation.
I appreciate any help in advance!