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

ng build --dev heads to Error: Optimization error [main.fe9785e49a33b769.js]: SyntaxError: Unexpected token: punc ({) #538

Closed
AdamKundracik opened this issue Dec 14, 2022 · 4 comments

Comments

@AdamKundracik
Copy link

Angular version: 14.2.0

node version" 16.14.0

typescript version: 4.8.4

Hi everyone,
I'm fighting with weird problem. After running

ng build --dev --projet="project name"

my app don't want to build

it throws me this error on multiple files

Error: Optimization error [libs_frontend_domains_admin_companies_profile_feature_src_index_ts.2db0213594e6cb91.js]: SyntaxError: Unexpected token: punc ({)
or
Error: Optimization error [main.fe9785e49a33b769.js]: SyntaxError: Unexpected token: punc ({)

After trying to find error I found this error

Error: Optimization error [main.fe9785e49a33b769.js]: SyntaxError: Unexpected token: punc ({) at js_error (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:554:11) at croak (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:1278:9) at token_error (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:1286:9) at unexpected (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:1292:9) at as_property_name (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:3082:20) at concise_method_or_getset (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:2735:20) at class_ (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:2691:22) at statement (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:1466:24) at _embed_tokens_wrapper (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:1343:26) at block_ (/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:2178:20) at /Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/@angular-devkit+build-angular@14.2.10_t4wyd7xvdi4piymolsbdpzpxnu/node_modules/@angular-devkit/build-angular/src/webpack/plugins/javascript-optimizer-plugin.js:154:55 at async Promise.all (index 43) at async /Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/@angular-devkit+build-angular@14.2.10_t4wyd7xvdi4piymolsbdpzpxnu/node_modules/@angular-devkit/build-angular/src/webpack/plugins/javascript-optimizer-plugin.js:158:21

I'm not using terser directly in package.json , and I don't know which package would use it.

What can be an issue?

Thanks

@alexander-akait
Copy link
Member

It means you have a syntax problem in the file, which is not supported by terser (or it is invalid syntax), please open an issue in the ng repo, I see javascript-optimizer-plugin, so the problem can be there, we can't fix it here, because we just wrapper to run minifiers (not more). Also I don't see reproducible example, so I can't investigate, you can try to debug it locally

(/Users/adam/Desktop/work/meta_dev/respect/node_modules/.pnpm/terser@5.14.2/node_modules/terser/dist/bundle.min.js:554:11) at croak

@AdamKundracik
Copy link
Author

I found error.. It was in latest ES2022 in tsconfig -> target.
I changed it to ES2020 and it works fine. Looks like it has some problems with parsing

@alexander-akait
Copy link
Member

Yeah, sounds like terser doesn't handle a new syntax, you can open a new issue about it, because it is not good

@AdamKundracik
Copy link
Author

Check issue here:

#539

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

No branches or pull requests

2 participants