next-seo
next-seo copied to clipboard
Optional chaining operator doesn't compile and doesn't work in older browsers
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
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
Got the same issue
Had the same issue, I solved deploying to Vercel by upgrading the version of node used from 12 to 14 in the Vercel settings.
Firefox 72, Windows 11
I also experience the same issue on older browsers
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)
@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. πΊπ¦
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.
@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.
Can someone test v5.2.0
? This contains a fix added by @snelsi πͺ
Can confirm 5.2.0 fixed issue in my project π
I was getting the same issue. Upgrading to 5.2 solve the issue :+1: