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

Unexpected token: punc ({) #59046

Closed
1 task done
lichbt-rk opened this issue Nov 29, 2023 · 8 comments
Closed
1 task done

Unexpected token: punc ({) #59046

lichbt-rk opened this issue Nov 29, 2023 · 8 comments
Assignees
Labels
bug Issue was opened via the bug report template. locked SWC Related to minification/transpilation in Next.js.

Comments

@lichbt-rk
Copy link

Link to the code that reproduces this issue

https://github.com/lichbt-rk/next-14-minify-error

To Reproduce

  1. create project with npx create-next-app@latest
  2. Add a class with static property
  3. set swcMinify is false in next.config.js
  4. Run npm run build

Current vs. Expected behavior

Current: got the error
`> build

next build

⚠ Disabling SWC Minifer will not be an option in the next major version. Please report any issues you may be experiencing to https://github.com/vercel/next.js/issues
✓ Linting and checking validity of types
▲ Next.js 14.0.4-canary.25

Failed to compile.

../pages/TestClass.js from Terser
Unexpected token: punc ({) [../pages/TestClass.js:174,10]
at js_error (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:32780)
at croak (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:43882)
at token_error (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:43989)
at unexpected (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:44055)
at as_property_name (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:68487)
at concise_method_or_getset (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:64746)
at class_ (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:64098)
at statement (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:46908)
at embed_tokens_wrapper (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:45013)
at block
(/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:56881)

../pages/index.js from Terser
Unexpected token: punc ({) [../pages/index.js:197,10]
at js_error (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:32780)
at croak (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:43882)
at token_error (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:43989)
at unexpected (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:44055)
at as_property_name (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:68487)
at concise_method_or_getset (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:64746)
at class_ (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:64098)
at statement (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:46908)
at embed_tokens_wrapper (/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:45013)
at block
(/home/lichbt/Projects/next-14-minify-error/node_modules/next/dist/compiled/terser/bundle.min.js:1:56881)

Build failed because of webpack errors
`

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

node: 18.17.1
next: 14.0.3
os: ubuntu 20.04 LTS

Which area(s) are affected? (Select all that apply)

SWC transpilation

Additional context

No response

@lichbt-rk lichbt-rk added the bug Issue was opened via the bug report template. label Nov 29, 2023
@github-actions github-actions bot added the SWC Related to minification/transpilation in Next.js. label Nov 29, 2023
@milap1296
Copy link

milap1296 commented Nov 29, 2023

I can also confirm, facing the same issue!

@m19
Copy link

m19 commented Dec 1, 2023

I believe my comment on another issue is related.

When I set swcMinify: false I get Unexpected token: punc ({ too. This happens on 14.0.3 and not 14.0.1 (the version I was using before this). In 14.0.1 I can set swcMinify: false and everything compiles without issue.

@lichbt-rk
Copy link
Author

lichbt-rk commented Dec 1, 2023

I believe my comment on another issue is related.

When I set swcMinify: false I get Unexpected token: punc ({ too. This happens on 14.0.3 and not 14.0.1 (the version I was using before this). In 14.0.1 I can set swcMinify: false and everything compiles without issue.

The error still occurs in version 14.0.1.

@kdy1 kdy1 self-assigned this Dec 4, 2023
@kdy1
Copy link
Member

kdy1 commented Dec 4, 2023

I started working on this 😄

@kdy1
Copy link
Member

kdy1 commented Dec 4, 2023

SWC transpiles static class properties to static blocks.

 export class TestClass {
    static currentDate = new Date()
 }

output:

             class TestClass {
                static{
                    this.currentDate = new Date();
                }
            }

but it seems like terser is not recognizing it properly

@kdy1
Copy link
Member

kdy1 commented Dec 11, 2023

Closing as fixed on canary.
Forked repro: https://github.com/kdy1/repro-next-59046

image

@kdy1 kdy1 closed this as completed Dec 11, 2023
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 Dec 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

No branches or pull requests

4 participants