swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

Error using next-mdx-remote. #35

Closed ari-motors-team closed 2 years ago

ari-motors-team commented 2 years ago

Hi, just upgraded my nextjs project to the latest versions yarn upgrade --latest and got this error:

./utils/parseMarkdown.js
Module parse failed: Optional chaining cannot appear in left-hand side (23:74)
File was processed with these loaders:
 * ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js
You may need an additional loader to handle the result of these loaders.
|                 const source = section.answer;
|                 const mdxSource = await serialize(source);
>                 if (parsedPage.faq.data?.attributes.sections?.length > 0) parsedPage.faq.data?.attributes.sections[index].answer = mdxSource;
|             }
|         }

I am not sure, which package caused the error. I assume the error came from next-mdx-remote, but it seems to be a problem with the loader. If its not, I will create another ticket their.

package.json

{
  "private": true,
  "license": "Unlicense",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "postbuild": "next-sitemap",
    "start": "next start",
    "deploy": "cd strapi; yarn; yarn upgrade; git add . ; git commit -m 'Update strapi'; git push heroku HEAD:main",
    "dumpdb": "scripts/dumpdb.sh"
  },
  "dependencies": {
    "@algolia/autocomplete-js": "^1.5.1",
    "@algolia/autocomplete-plugin-query-suggestions": "^1.5.1",
    "@algolia/autocomplete-plugin-recent-searches": "^1.5.1",
    "@phntms/next-gtm": "^0.1.0",
    "@tailwindcss/forms": "^0.4.0",
    "algoliasearch": "^4.12.0",
    "emailjs-com": "^3.2.0",
    "framer-motion": "^5.6.0",
    "idb-keyval": "^6.1.0",
    "memory-cache": "^0.2.0",
    "next": "^12.0.8",
    "next-mdx-remote": "3.0.8",
    "next-pwa": "^5.3.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-facebook-pixel": "^1.0.4",
    "react-instantsearch-dom": "^6.19.0",
    "react-intersection-observer": "^8.33.0",
    "react-lazy-hydration": "^0.1.0",
    "react-responsive": "^9.0.0-beta.4",
    "react-youtube": "^7.14.0",
    "tailwind-scrollbar": "^1.3.1"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.2",
    "base-64": "^1.0.0",
    "eslint": "8.6.0",
    "eslint-config-next": "12.0.8",
    "next-sitemap": "^1.9.9",
    "postcss": "^8.4.5",
    "sharp": "^0.29.1",
    "tailwindcss": "^3.0.13"
  }
}
ari-motors-team commented 2 years ago

Ok, seems like the optional chaining in my code caused the problem. I wonder, why it worked before. I'll close the issue.