typescriptnestjsswc

Nest JS and Typescript with SWC is not compiling dist folder correctly


Hi all I'm getting this error. I have surf through all the internet but haven't found any useful solution and even the GitHub discussion was not even useful for me on this topic below are the some screenshots related to the same topic and the error I'm getting.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

I have tried verything using tspath and removing dist folder and removing package-lock.json node_modules, but nothing worked


Solution

  • Finally, I found the solution for this issue.

    This is occuring due to the swc compiler configuration either you have to correct your paths in .swcrc and tsconfig files OR you can try the below solutions.

    There are 2 solutions out there you can use to get rid of this error

    Solution 1

    Downgrade or upgrade your @swc/core package to v1.3.78

    npm install -D @swc/core@1.3.78
    

    Note This trick worked for me, but it didn't work after removing node_modules, package-lock.json and dist and re-installing all the packages again. I had to reinstall the swc/core package with above version seperately to make it work. I don't know if it has something to do with node(18.17.1) and npm(9.8.1) versions

    Solution 2

    Install @swc-node/register as dev dependecy

    npm install -D @swc-node/register
    

    and replace your start or dev script which ever you prefer with the below script.

    "start": "node -r '@swc-node/register' --watch --enable-source-maps src/main.ts"
    

    Hopefully, these solutions will solve your problem now.

    These solutions worked for me, let me know in the discussion if there is a better solution for this problem.