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

"JS_Parse_Error [SyntaxError]: Unterminated string constant" In moment.js During Bundle #178

Closed
sprankhub opened this issue Jun 28, 2023 · 1 comment

Comments

@sprankhub
Copy link

When I run magepack bundle, I get the following error:

$ /usr/bin/npx magepack bundle
ℹ Using bundling config from "/var/www/share/dev.shop.de/releases/53/magepack.config.js".
ℹ Creating bundles for "pub/static/frontend/Magento/shoptheme/de_DE".
ℹ Creating bundles for "pub/static/frontend/Magento/shoptheme/en_US".
✔ Generated bundle "category"   - 0 kB (0 kB gz).
✔ Generated bundle "cms"        - 1 kB (0 kB gz).
✔ Generated bundle "product"    - 114 kB (36 kB gz).
✔ Generated bundle "checkout"   - 230 kB (47 kB gz).
✔ Generated bundle "category"   - 0 kB (0 kB gz).
✔ Generated bundle "cms"        - 1 kB (0 kB gz).
✔ Generated bundle "product"    - 114 kB (36 kB gz).
✔ Generated bundle "checkout"   - 230 kB (47 kB gz).
/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:549
    throw new JS_Parse_Error(message, filename, line, col, pos);
          ^

JS_Parse_Error [SyntaxError]: Unterminated string constant
    at js_error (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:549:11)
    at parse_error (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:685:9)
    at /var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:836:48
    at /var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:1049:24
    at Object.next_token [as input] (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:1084:40)
    at peek (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:1253:56)
    at next (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:1258:24)
    at subscripts (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:3298:13)
    at expr_atom (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:2563:20)
    at maybe_unary (/var/www/share/dev.shop.de/releases/53/node_modules/terser/dist/bundle.min.js:3414:19) {
  filename: '0',
  line: 827,
  col: 42362,
  pos: 267112
}

Node.js v18.16.0

This happens after a big update from Magento 2.4.4-p4 to 2.4.6-p1 including Node package updates, especially a MagePack update from 2.8.0 to 2.11.2.

I debugged this and found out that the error happens for lib/web/moment.js. As soon as I remove the mapping moment: 'moment' from my magepack.config.js, the error is gone. I verified that the file exactly matches https://github.com/magento/magento2/blob/2.4.6-p1/lib/web/moment.js.

Any idea?

@sprankhub
Copy link
Author

I noticed that pub/static/frontend/Magento/shoptheme/de_DE/moment.min.js is already broken. Looked into the static content deployment output and found a lot of "Unclosed regex pattern at position" errors. This was caused by tedivm/jshrink version 1.6.7. Updating to 1.6.8 solved the issue. See tedious/JShrink#135.

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

1 participant