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
I found this bug when I add Swagger to one of my services. In that one, the problem arises with a DTO 馃憤
export class CreateOrgDto {
...
storageconf: StorageConf;
//storageconf: string;
}
Here "StorageConf" is an Enum. It works OK when it is a string (comment one line and uncomment the other).
When creating the sample to share in the repo with the "minimum reproduction code", the issue generalised. It happens always in that code, and it is really a very basic one.
The issue is not consistent. In the provided sample repo, it happens always.
In a larger project that I have with several independent micro-services (separated in different apps), all set to ES2022, it only happens with the one that has the DTO above, all other compile correctly. Actually, as mentioned, even this one compiles correctly if "storageconf" is of type string instead of "StorageConf" enum.
I was expecting correct compilation. Instead. I get:
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:...\NestJsSwaggerBug\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///C:/.../NestJsSwaggerBug/dist/app.controller.js:26:112
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at loadESM (node:internal/process/esm_loader:28:7)
at handleMainPromise (node:internal/modules/run_main:113:12)
Package version
7.3.1
NestJS version
10.3.0
Node.js version
20.11.0
In which operating systems have you tested?
macOS
Windows
Linux
Other
IDE: VsCode vs1.88.1
Package manager: yarn v4.1.1
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Current behavior
I found this bug when I add Swagger to one of my services. In that one, the problem arises with a DTO 馃憤
Here "StorageConf" is an Enum. It works OK when it is a string (comment one line and uncomment the other).
When creating the sample to share in the repo with the "minimum reproduction code", the issue generalised. It happens always in that code, and it is really a very basic one.
Important points:
the javascript code created in "dist" for the DTO above is:
The problem is with the 'require" inside _OPENAPI_METADATA_FACTORY()
This issue may be linked to ESM Build Issues #1450 , which seems to depend on build: generate multiple formats (cjs, esm) #8736 , which points to this recent post in Joyee Cheung's Blog. I did try running with flag --experimental-require-module , but it did not make any difference.
The issue is not consistent. In the provided sample repo, it happens always.
In a larger project that I have with several independent micro-services (separated in different apps), all set to ES2022, it only happens with the one that has the DTO above, all other compile correctly. Actually, as mentioned, even this one compiles correctly if "storageconf" is of type string instead of "StorageConf" enum.
Minimum reproduction code
https://github.com/yaluba1/NestJsSwaggerBug
Steps to reproduce
Expected behavior
I was expecting correct compilation. Instead. I get:
Package version
7.3.1
NestJS version
10.3.0
Node.js version
20.11.0
In which operating systems have you tested?
Other
IDE: VsCode vs1.88.1
Package manager: yarn v4.1.1
The text was updated successfully, but these errors were encountered: