next-seo icon indicating copy to clipboard operation
next-seo copied to clipboard

Optional chaining operator doesn't compile and doesn't work in older browsers

Open iipanda opened this issue 2 years ago β€’ 12 comments

Describe the bug The ?. somehow doesn't get compiled by TypeScript (it is normally replaced during compilation, see the compiled code here), and it ends up in the bundle, causing the app using next-seo to crash in older browsers that don't support that operator.

Here's our Sentry error message caused by this:

SyntaxError: Unexpected token .
  at ? (./node_modules/next-seo/lib/next-seo.module.js:210:14)

Reproduction Just open this CodeSandbox in new tab, and search chunks/pages/index[garbage].js for ?. I set up this CodeSandbox to run a production build and not in dev mode https://codesandbox.io/s/pensive-danny-5s7mzd

iipanda avatar Feb 26 '22 21:02 iipanda

Can confirm this is an issue. Development builds without problems, fails to compile with the same error in vercel.

next@^12.1.0 using swc

medv avatar Mar 01 '22 03:03 medv

Got the same issue

futantan avatar Mar 02 '22 13:03 futantan

Had the same issue, I solved deploying to Vercel by upgrading the version of node used from 12 to 14 in the Vercel settings.

astanb avatar Mar 05 '22 13:03 astanb

image Firefox 72, Windows 11

snelsi avatar Mar 09 '22 14:03 snelsi

I also experience the same issue on older browsers

prince272 avatar Mar 12 '22 17:03 prince272

Maybe this can help:

const withTM = require('next-transpile-modules')(['next-seo']); // pass the modules you would like to see transpiled

module.exports = withTM(nextConfig)

futantan avatar Mar 14 '22 10:03 futantan

@snelsi Thank you for your work. Since this PR is still pending and I'm blocked, I attempted to import this fork's branch via yarn add next-seo@https://github.com/snelsi/next-seo.git#bug/932-update-babel-config

But my project is unable to build due to this error: ModuleNotFoundError: Module not found: Error: Can't resolve 'next-seo'

Let me know if you have any suggestions on how I can work around this. πŸ‡ΊπŸ‡¦

sos0 avatar Mar 16 '22 20:03 sos0

I've confirmed the issue doesn't exist the below older version, temporary workaround:

npm install [email protected] --save

I had the same issue as @sos0 , if I try to use the patch suggested it doesn't actually end up exporting the module.

technion avatar Mar 23 '22 03:03 technion

@sos0 @technion This package has an extra build step when it's published, so you can't use Github repo directly as a package declaration.

Try this, I published my fork as a npm package: npm i @snelsi/next-seo

Swap all imports of next-seo with @snelsi/next-seo. You can swap back once the original package is patched.

snelsi avatar Mar 23 '22 08:03 snelsi

Can someone test v5.2.0? This contains a fix added by @snelsi πŸ’ͺ

garmeeh avatar Mar 23 '22 08:03 garmeeh

Can confirm 5.2.0 fixed issue in my project πŸŽ‰

snelsi avatar Mar 23 '22 16:03 snelsi

I was getting the same issue. Upgrading to 5.2 solve the issue :+1:

armandabric avatar Mar 28 '22 12:03 armandabric