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

Sourcemaps stop working due to multiline comment + CRLF line endings #32470

Closed
leroydev opened this issue Dec 13, 2021 · 12 comments · Fixed by #32566
Closed

Sourcemaps stop working due to multiline comment + CRLF line endings #32470

leroydev opened this issue Dec 13, 2021 · 12 comments · Fixed by #32566
Labels
locked SWC Related to minification/transpilation in Next.js.

Comments

@leroydev
Copy link
Contributor

leroydev commented Dec 13, 2021

What version of Next.js are you using?

Happens in at least 12.0.0, 12.0.7, 12.0.8-canary.5 and 12.0.8-canary.8.

What version of Node.js are you using?

16.13.1

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying your application?

next dev

Describe the Bug

When my function has a multiline comment, sourcemaps break.
I can't set a breakpoint on the first console.log and the variables in "Scope" make no sense:
image

Expected Behavior

I expected the same behavior as when the multiline comment is removed, so being able to set a breakpoint on the first console.log and the "Scope" looking like this:
image

To Reproduce

  • Clone https://github.com/leroydev/nextjs-sourcemaps (it's a minimal working example, just 1 extra commit on top of npx create-next-app@latest --ts)
  • Execute yarn to install the dependencies
  • Run yarn dev to start Next.js in development
  • Open http://localhost:3000
  • Open Chrome DevTools -> CTRL + P -> LogSomeText.ts
  • Set breakpoints inside the function and reload

You can see that when you completely remove the multiline comment in LogSomeText.ts, you can set a breakpoint on the first console.log again and the variables in the scope make sense again.

@leroydev leroydev added the bug Issue was opened via the bug report template. label Dec 13, 2021
@balazsorban44
Copy link
Member

I'm not really sure what the bug is, I cannot reproduce what you are describing (eg.: I always get what you are describing on the second image).

As a note, the LogSomeText.ts is inside the pages folder. Every file inside the pages is expected to have a default import. If your component isn't representing a page, move it outside of that folder.

@leroydev
Copy link
Contributor Author

leroydev commented Dec 14, 2021

@balazsorban44 Hmm which browser and OS are you using? And are you using my repository? Because I can imagine that without TypeScript, you won't have this problem.

I'm aware that having it in the pages folder is against best practices. It doesn't matter for this bug though, in our private codebase we have this exact file in the src folder and it still happens. Each file that has multiline comments has messed up breakpoints in our private codebase.

Edit: On another Windows PC with Chrome I can't reproduce it either.. Really weird, because on my own PC with a clean clone of my test repository, I can reproduce it everytime, even on Firefox..

@leroydev
Copy link
Contributor Author

leroydev commented Dec 14, 2021

@balazsorban44 When changing the linefeed from CRLF to LF and trying again, the issue is resolved. So it seems to be a bug when combining CRLF with multiline comments. Can you try if you can reproduce it with CRLF linefeeds enabled in LogSomeText.ts? You can change the linefeed in VSCode in the bottom right.

We can use this as a workaround but I feel like this bug should also be fixed, because it's very hard to debug when you run into this issue.. I think CRLF is the default on Git on Windows because CRLF is the native line ending on Windows.

@balazsorban44
Copy link
Member

I am on Linux, and I used your reproduction.

You are correct though, I could reproduce it by changing the line ending to CRLF and resave the LogSomeText.ts file.

It happens when using the SWC transform.

@balazsorban44 balazsorban44 reopened this Dec 14, 2021
@balazsorban44 balazsorban44 added SWC Related to minification/transpilation in Next.js. kind: bug and removed bug Issue was opened via the bug report template. labels Dec 14, 2021
@leroydev leroydev changed the title Sourcemaps stop working due to multiline comment Sourcemaps stop working due to multiline comment + CRLF line endings Dec 14, 2021
@leroydev
Copy link
Contributor Author

leroydev commented Dec 15, 2021

I think this might possibly be fixed in swc-project/swc#3023, which has been released in swc_ecma_codegen 0.83.2.
I can't get a local Next.js version to work with a custom SWC build though, so I unfortunately can't verify this.

@kodiakhq kodiakhq bot closed this as completed in #32566 Dec 16, 2021
kodiakhq bot pushed a commit that referenced this issue Dec 16, 2021
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


This applies

 - swc-project/swc#3051

Fixes #32553

 - swc-project/swc#3023

Fixes #32470
@leroydev
Copy link
Contributor Author

leroydev commented Dec 16, 2021

@balazsorban44 Unfortunately, this issue wasn't fixed by #32566.
I upgraded https://github.com/leroydev/nextjs-sourcemaps to 12.0.8-canary.8, deleted .next, executed yarn and yarn dev and still run into the same issue.
Can you reopen this issue please? :)

@balazsorban44 balazsorban44 reopened this Dec 19, 2021
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


This applies

 - swc-project/swc#3051

Fixes vercel#32553

 - swc-project/swc#3023

Fixes vercel#32470
@kdy1 kdy1 self-assigned this Oct 13, 2022
@prometixX
Copy link

prometixX commented Jan 25, 2023

I also experienced the issue with line ending CRLF breaking my Vscode debugger and resulting in breakpoints jumping and "old code" in the debugger.

I only experienced this in server side Nextjs code.
For example in an API route when I invoked a function that I imported from another file the breakpoints in this function did not work properly. I got jumping breakpoints and the debugger stopped at code parts that should not be invoked anymore (for example when I moved code around).

When I changed the line ending of this file (of the imported function) to CRLF to LF, everything worked normally.

I used the following versions:

  • next: 13.1.1,
  • react: 18.2.0
  • typescript: ^4.9.4
  • node: 18.12.1

And the default launch script for vscode from the Nextjs docs.

@kdy1
Copy link
Member

kdy1 commented Jan 25, 2023

@prometixX Can you try updating next?

@prometixX
Copy link

@prometixX Can you try updating next?

Its really strange, right now I cant replicate the problem anymore, but I did not update.
Before I always had this issue when the file hat CRLF endings and switching to LF fixed it. (Tried that multiple times)
Maybe the issue on my side was related to something else and Vscode (or the debugger) could not refresh the code.

If this debugging issue occurs again, I will check if LF line endings fixes it again, but for now I cant replicate it anymore.

@kdy1
Copy link
Member

kdy1 commented Mar 13, 2023

Can someone provide a repro? I think this is fixed by swc-project/swc@26a0c13

@kdy1 kdy1 removed their assignment Mar 13, 2023
@leroydev
Copy link
Contributor Author

leroydev commented Oct 5, 2023

@kdy1 Sorry for the late response, I updated Next.js and React to the latest version in my reproduction repository and the problem is resolved:
image

@leroydev leroydev closed this as completed Oct 5, 2023
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants