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

@swc/core@1.3.51 does not return sourcemap for type-only files, causes error in updateSourceMap #1996

Closed
erikthiem-immuta opened this issue Apr 19, 2023 · 1 comment · Fixed by #2062

Comments

@erikthiem-immuta
Copy link

erikthiem-immuta commented Apr 19, 2023

Search Terms

SWC

Expected Behavior

I am using ts-node with the --swc flag. I expect it to work. It works fine for me on SWC < 1.3.50

Actual Behavior

I tried upgrading to SWC >= 1.3.50 today and it caused ts-node to not work. I unfortunately did not see much useful output. If there is a way to get more useful output to fix this, I am happy to try it.

Steps to reproduce the problem

Upgrade to SWC >= 1.3.50

Minimal reproduction

Be on ts-node version 10.9.1 and SWC version 1.3.50 and try to use ts-node with the --swc flag.

Specifications

  • ts-node version: 10.9.1
  • node version: 18.x
  • TypeScript version: 4.8.4
  • tsconfig.json, if you're using one:
"ts-node": {
    "swc": true
}
  • package.json:
    The relevant part would be:
`... node_modules/ts-node/dist/bin.js --swc --transpile-only index.ts`
  • Operating system and version: Mac
  • If Windows, are you using WSL or WSL2?:
@koh110
Copy link

koh110 commented Apr 26, 2023

I have same issue.
After changing the version of @swc/core@1.3.51, I encountered an error in --swc mode.
The cause of the error seems to be import a file that only exports types.

Since a file that only exports types does not generate a SourceMap file when using @swc/core@1.3.51.
So it seems that updateSourceMap throw error because undefined is given to JSON.parse.
ref

I have confirmed that the error does not occur when passing {} instead of undefined.

function updateSourceMap(sourceMapText: string, fileName: string) {
  const sourceMap = JSON.parse(sourceMapText ?? {});

I want to send PR, but I still can't think of how to write tests.

@cspotcode cspotcode changed the title SWC >= 1.3.50 seems to have introduced breaking issues with ts-node @swc/core@1.3.51 does not return sourcemap for type-only files, causes error in updateSourceMap Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants