Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js SyntaxError: Unexpected token 'export'

enter image description here

I'm having the following error in the console when I try to run my api written in node js.

Can you tell me which is the problem.

like image 312
Paul Avatar asked Oct 25 '25 03:10

Paul


1 Answers

Importing is generally done at the top of your files and looks like this:

import User, {schema} from './model.js'

Exporting is generally done at the bottom of your files and looks like this:

module.exports = {User, schema}

And the specific reason why you get the error is because export is not used that way.

Here is a direct quote from Web Docs:

export DefaultExport from 'bar.js'; // Invalid

like image 69
codemonkey Avatar answered Oct 27 '25 19:10

codemonkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!