Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected token 'export' #23

Closed
grenzionky opened this issue Mar 28, 2023 · 5 comments
Closed

Unexpected token 'export' #23

grenzionky opened this issue Mar 28, 2023 · 5 comments

Comments

@grenzionky
Copy link

I have a next.js typescript project with MUI, and I'm getting this error:

error - node_modules/mui-address-autocomplete/index.js:1
export {AddressAutocomplete} from './AddressAutocomplete';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at mui-address-autocomplete (.next/server/pages/application.js:142:18)
    at __webpack_require__ (.next/server/webpack-runtime.js:33:42) {
  page: '/'
}

Here's my tsconfig.json:

{
	"compilerOptions": {
		"target": "es2017",
		"lib": ["dom", "dom.iterable", "esnext"],
		"allowJs": true,
		"skipLibCheck": true,
		"strict": true,
		"forceConsistentCasingInFileNames": true,
		"noEmit": true,
		"esModuleInterop": true,
		"module": "esnext",
		"moduleResolution": "node",
		"resolveJsonModule": true,
		"isolatedModules": true,
		"jsx": "preserve",
		"incremental": true,
		"noUncheckedIndexedAccess": true
	},
	"ts-node": { "esm": true },
	"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.mjs"],
	"exclude": ["node_modules"]
}

Not sure what the problem is. ESNext should support the export keyword just fine. it works everywhere else in my project...

@Zenoo
Copy link
Owner

Zenoo commented Mar 28, 2023

Could you create a minimal project with this error on CodeSandbox?
This is probably a misconfiguration in your project.

@grenzionky
Copy link
Author

https://codesandbox.io/s/aectionate-jasper-7uhiih?file=/pages/index.tsx

here ya go. still getting the error

@Zenoo
Copy link
Owner

Zenoo commented Mar 28, 2023

You're using an outdated version of Next, you can update it and use the module transpilation option in the config as described here: https://nextjs.org/docs/advanced-features/compiler#module-transpilation

Or use the package next-transpile-modules.

See https://stackoverflow.com/questions/65936222/next-js-syntaxerror-unexpected-token-export

@grenzionky
Copy link
Author

it works! thanks! how did you go about finding the answer if you dont mind explaining, thanks

@Zenoo
Copy link
Owner

Zenoo commented Mar 30, 2023

It's simply trial and error, and a lot of Google searching :D

@Zenoo Zenoo closed this as completed Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants