magesuite / magepack

Next generation Magento 2 advanced JavaScript bundler.
Open Software License 3.0
438 stars 91 forks source link

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

Closed sprankhub closed 1 year ago

sprankhub commented 1 year ago

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 commented 1 year ago

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 https://github.com/tedious/JShrink/issues/135.