You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When building the application with the Swagger plugin enabled in nest-cli.json, the paths to types in the node_modules folder are semi-hardcoded to go up one folder from the root of the compiled files.
In a fresh NestJS project this works fine, because the dist/ directory is where the compiled files live. However, when you have additional folders with source files besides src/ that are compiled, dist will look something like this:
dist/
src/
migration/
If this is the case, then the build breaks when returning types that are imported from external packages in the node_modules folder. Consider the following example:
As you can see, the require call only goes up two directories to the dist/ folder,
where node_modules/ is not present, obviously.
This results in the following error when running NestJS:
Error: Cannot find module '../../node_modules/typeorm/query-builder/result/DeleteResult'
Require stack:
- /home/denzo/Code/nest-swagger-typeorm-repro/dist/src/photo/photo.controller.js
- /home/denzo/Code/nest-swagger-typeorm-repro/dist/src/photo/photo.module.js
- /home/denzo/Code/nest-swagger-typeorm-repro/dist/src/app.module.js
- /home/denzo/Code/nest-swagger-typeorm-repro/dist/src/main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:973:15)
at Function.Module._load (internal/modules/cjs/loader.js:855:27)
at Module.require (internal/modules/cjs/loader.js:1033:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/denzo/Code/nest-swagger-typeorm-repro/dist/src/photo/photo.controller.js:38:46)
at Module._compile (internal/modules/cjs/loader.js:1144:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
at Module.load (internal/modules/cjs/loader.js:993:32)
at Function.Module._load (internal/modules/cjs/loader.js:892:14)
at Module.require (internal/modules/cjs/loader.js:1033:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/denzo/Code/nest-swagger-typeorm-repro/dist/src/photo/photo.controller.js',
'/home/denzo/Code/nest-swagger-typeorm-repro/dist/src/photo/photo.module.js',
'/home/denzo/Code/nest-swagger-typeorm-repro/dist/src/app.module.js',
'/home/denzo/Code/nest-swagger-typeorm-repro/dist/src/main.js'
]
}
If the plugin is disabled, or any additional directories besides src/ are ignored in the tsconfig, the code will build and run correctly.
Expected behavior
The preferred solution would be for the imports from node_modules/ to be handled correctly in any case, and not reliant on the compiled source files to be in the root of dist.
If this is not possible, some additional documentation to prevent this from happening would be preferred.
Minimal reproduction of the problem with instructions
I have set up a minimal reproduction repository here:
What is the motivation / use case for changing the behavior?
Whether or not it is best practice to have multiple directories being compiled into the dist/ folder, it's a very common case, and this error is very vague and mysterious for any beginners encountering this. However, I don't think a minor variation in directory structure should be a problem when using the Swagger plugin.
Environment
Nest version: 6.7.2 (reproduction repo), 6.10.14 (my production environment where I encountered it).
NestJS Swagger version: 4.1.14
For Tooling issues:
- Node version: 13.6.0
- Platform: Linux
The text was updated successfully, but these errors were encountered:
I'm submitting a...
Current behavior
When building the application with the Swagger plugin enabled in
nest-cli.json
, the paths to types in thenode_modules
folder are semi-hardcoded to go up one folder from the root of the compiled files.In a fresh NestJS project this works fine, because the
dist/
directory is where the compiled files live. However, when you have additional folders with source files besidessrc/
that are compiled, dist will look something like this:If this is the case, then the build breaks when returning types that are imported from external packages in the
node_modules
folder. Consider the following example:This results in the following call in the compiled file:
As you can see, the require call only goes up two directories to the
dist/
folder,where
node_modules/
is not present, obviously.This results in the following error when running NestJS:
If the plugin is disabled, or any additional directories besides
src/
are ignored in the tsconfig, the code will build and run correctly.Expected behavior
The preferred solution would be for the imports from
node_modules/
to be handled correctly in any case, and not reliant on the compiled source files to be in the root ofdist
.If this is not possible, some additional documentation to prevent this from happening would be preferred.
Minimal reproduction of the problem with instructions
I have set up a minimal reproduction repository here:
https://github.com/DenzoNL/nestjs-swagger-plugin-repro
What is the motivation / use case for changing the behavior?
Whether or not it is best practice to have multiple directories being compiled into the
dist/
folder, it's a very common case, and this error is very vague and mysterious for any beginners encountering this. However, I don't think a minor variation in directory structure should be a problem when using the Swagger plugin.Environment
The text was updated successfully, but these errors were encountered: