Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: 'Invalid value used in weak set' in Nestia Swagger Generation After Introducing PrismaModule #631

Closed
Val0429 opened this issue Sep 28, 2023 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request question Further information is requested

Comments

@Val0429
Copy link

Val0429 commented Sep 28, 2023

Firstly thanks for the excellent work! It works very well and we decided to put nestia into our code base.

Summary

The bug manifests during the Nestia Swagger generation process. Initially, it ran smoothly until I added a straightforward PrismaModule following the official NestJS documentation. Strangely, even without importing it explicitly, the Swagger generation now throws an error: "Invalid value used in weak set."

I've made a github project to demonstrate this bug.
https://github.com/Val0429/nestia-swagger-weakmap-issue

git checkout 75d577c: It's the code which works
image

git checkout main: Not working
image

@samchon samchon self-assigned this Oct 5, 2023
@samchon samchon added bug Something isn't working enhancement New feature or request question Further information is requested labels Oct 5, 2023
@samchon
Copy link
Owner

samchon commented Oct 5, 2023

At first, change input property of nestia.config.ts file to be src/**/*.controller.ts like below, then you can avoid the bug.

For reference, the reason of the bug is occured by below code, and such WeakSet cannot store string value what you've exported through prisma.module.ts file.

I'll fix this bug ASAP. Thanks for special reporting.

Change nestia.config.ts file like below

/*
 * File: nestia.config.ts
 * File Created: 2023-09-21 04:29:25
 * Author: Val Liu <[email protected]>
 *
 * -----
 * Last Modified: 2023-09-23 01:11:33
 * Modified By: Val Liu
 * -----
 */

import { INestiaConfig } from "@nestia/sdk";

export const NESTIA_CONFIG: INestiaConfig = {
    /**
     * Building `swagger.json` is also possible.
     *
     * If not specified, you can't build the `swagger.json`.
     */
    swagger: {
        /**
         * Output path of the `swagger.json`.
         *
         * If you've configured only directory, the file name would be the `swagger.json`.
         * Otherwise you've configured the full path with file name and extension, the
         * `swagger.json` file would be renamed to it.
         */
        output: "packages/swagger.json",

        servers: [
            {
                url: "http://localhost:3000",
                description: "Local Server",
            },
        ],
    },

    /**
     * List of files or directories containing the NestJS controller classes.
     */
    input: ["src/**/*.controller.ts"],

    /**
     * Output directory that SDK would be placed in.
     *
     * If not configured, you can't build the SDK library.
     */
    output: "src/api",

    /**
     * Target directory that SDK distribution files would be placed in.
     *
     * If you configure this property and runs `npx nestia sdk` command,
     * distribution environments for the SDK library would be generated.
     *
     * After the SDK library generation, move to the `distribute` directory,
     * and runs `npm publish` command, then you can share SDK library with
     * other client (frontend) developers.
     */
    // distribute: "packages/api",

    /**
     * Allow simulation mode.
     *
     * If you configure this property to be `true`, the SDK library would be contain
     * simulation mode. In the simulation mode, the SDK library would not communicate
     * with the real backend server, but just returns random mock-up data
     * with requestion data validation.
     *
     * For reference, random mock-up data would be generated by `typia.random<T>()`
     * function.
     *
     * @default false
     */
    // simulate: true,
};
export default NESTIA_CONFIG;

My code occuring the bug

export namespace ReflectAnalyzer {
export async function analyze(
unique: WeakSet<any>,
file: string,
): Promise<IController[]> {
const module: IModule = await (async () => {
try {
return await import(file);
} catch (exp) {
console.log(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
);
console.log(`Error on "${file}" file. Check your code.`);
console.log(exp);
console.log(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
);
process.exit(-1);
}
})();
const ret: IController[] = [];
for (const tuple of Object.entries(module)) {
if (unique.has(tuple[1])) continue;
else unique.add(tuple[1]);

Your prisma.module.ts file

export const PRISMA_INJECTION_TOKEN = "PrismaService";

@samchon samchon closed this as completed in db199c8 Oct 5, 2023
samchon added a commit that referenced this issue Oct 5, 2023
Fix #631 - when non-class value being exported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants