swc-node icon indicating copy to clipboard operation
swc-node copied to clipboard

typescript metadata work error(nestjs)

Open pincman opened this issue 4 years ago • 3 comments

.swcrc

{
    "jsc": {
        "loose": true,
        "target": "es2020",
        "parser": {
            "syntax": "typescript",
            "decorators": true
        },
        "transform": {
            "legacyDecorator": true,
            "decoratorMetadata": true
        }
    },
    "module": {
        "type": "commonjs",
        "strict": true,
        "strictMode": true,
        "lazy": true,
        "noInterop": true
    }
}

error image

pincman avatar Jun 26 '21 01:06 pincman

Could you provide a minimal code snippet to reproduce this issue?

Brooooooklyn avatar Jun 27 '21 16:06 Brooooooklyn

@Brooooooklyn My code

@Delete()
    @SerializeOptions({ groups: ['category-list'] })
    async destroyMulti(
        @Query()
        { page, limit }: QueryCategoryDto,
        @Body()
        { trash, categories }: DeleteCategoryMultiDto,
    ) {
        return this.categoryService.deletePaginate(
            categories,
            {
                page,
                limit,
            },
            {},
            trash,
        );
    }

and if running by @swc/register every thing is work fine

const runner = nodemon({
        script: 'src/main.ts',
        ext: 'js,json,ts',
        watch: ['src'],
        ignore: ['.git', 'node_modules', 'dist', 'scripts'],
        execMap: {
            ts: 'node -r @swc/register -r module-alias/register',
        },
        env: {
            NODE_ENV: environment(),
        },
        cwd: path.resolve(__dirname, '..', '..'),
        spawn: true,
    });
    runner.once('start', () => {
        console.log();
        console.log('Server has started:');
        if (urls.length > 0) {
            console.log(`- Local: ${chalk.green.underline(urls[0])}`);
        }
        if (urls.length > 1) {
            console.log(`- Network: ${chalk.green.underline(urls[1])}`);
        }
    });
    runner.on('restart', () => {
        console.log();
        console.log(chalk.yellow('Server is in restarting...'));
    });

image but when change to @swc-node/register,will get this error

 execMap: {
            ts: 'node -r @swc-node/register -r module-alias/register',
        },

image

I think the reason that is @swc-node/register not read the config file .swcrc,

{
    "sourceMaps": false,
    "jsc": {
        "loose": true,
        "parser": {
            "syntax": "typescript",
            "decorators": true
        },
        "transform": {
            "legacyDecorator": true,
            "decoratorMetadata": true
        },
        "target": "es2020",
        "externalHelpers": false
    },
    "module": {
        "type": "commonjs"
    }
}

how to read it for this project @swc-node?

pincman avatar Jun 28 '21 12:06 pincman