I am trying to setup NestJS API in NX monorepo with @nestjs/swagger CLI plugin enabled.
However, once I add the plugin into the webpack, I get error saying that the typescript emitted no output. Spend two days looking over the internet about this and couldn't find anything that would work (moving the options into project.json file, try to move it into anonymous plugin, changing of compiler from tsc to swc). Is it bug into the plugin or am I doing something wrong?
The output is:
ERROR in ./src/main.ts
Module build failed (from ../../node_modules/.pnpm/ts-loader@9.5.1_typescript@5.6.3_webpack@5.96.1/node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /home/kowalsky/Documents/testproject/apps/api/src/main.ts.
at makeSourceMapAndFinish (/home/kowalsky/Documents/testproject/node_modules/.pnpm/ts-loader@9.5.1_typescript@5.6.3_webpack@5.96.1/node_modules/ts-loader/dist/index.js:55:18)
at successLoader (/home/kowalsky/Documents/testproject/node_modules/.pnpm/ts-loader@9.5.1_typescript@5.6.3_webpack@5.96.1/node_modules/ts-loader/dist/index.js:42:5)
at Object.loader (/home/kowalsky/Documents/testproject/node_modules/.pnpm/ts-loader@9.5.1_typescript@5.6.3_webpack@5.96.1/node_modules/ts-loader/dist/index.js:23:5)
webpack compiled with 1 error (8456be451fa327b9)
Warning: command "webpack-cli build --node-env=production" exited with non-zero status code
It is just clean app, just initialized. No complex logic in it yet.
The example repo: https://github.com/PatrikValkovic/nestjs-swagger-plugin-failure
I figured it out, leaving the question if somebody has similar issue.
The tsconfig file has emitDelcarationOnly: true
configured causing the error above.
What is kind of weird is, that without the plugin, the compilation works as expected and the output is main.js
file in dist directory. However, once the plugin is enabled through
new NxAppWebpackPlugin({
// ...options
transformers: [
{
name: '@nestjs/swagger/plugin',
}
]
}),
once must also change the tsconfig file to contain "emitDeclarationOnly": false
. Why is the case I have honestly no idea.