2

I am working on a react nextjs project, and I suddenly ran into a SyntaxError: Unexpected token 'export' error.

I have read the solutions suggested here but I don't seem to understand it to correctly apply the suggested answers.

Is it something that has to do with nextjs compiling error? How do I best resolve it? SyntaxError: Unexpected token 'export

Here's a screenshot of my package.json package.json content

1
  • use import { BsInstagram } from "react-icons/bs"; instead of import { BsInstagram } from "react-icons/all"; Commented Dec 21, 2022 at 18:47

2 Answers 2

6

I later found a solution on Github - Syntax Error: Unexpected token export The issue has something to do with ES modules in next.js and the solution was to install next-transpile-modules using:

npm i next-transpile-modules.

Thereafter, I added the following to my next.config.js file:

const withTM = require('next-transpile-modules')(["react-icons"]);

module.exports = withTM({})

This solves the error (for me).

You will need to put the name of the affected node module in place of react-icons for it to work in your case.

Sign up to request clarification or add additional context in comments.

2 Comments

I already have content in the module.exports object. How do I combine with existing object? My code: pastebin.com/TtAxKqfC
Thank you good people, another note: if you have your own nextConfig, just input it inside withTM()
0

I too did face such a error in nextjs.
What I did was seperating the declaration and exporting statment of the function/constant into seperate lines.

Yet I'm not sure if it's the same issue you are going through, Could you please send the code of the next.config.js and whatever the scripts that are creating this error.

1 Comment

Thanks. Please find my next.config.js content below... /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, swcMinify: true, } module.exports = nextConfig

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.