'Node js SyntaxError: Unexpected token 'export'
Solution 1:[1]
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}
Ant 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
Solution 2:[2]
You are using ES6 syntax.
Node.js uses common.js syntax
You can use module.export syntax or you can use babel npm package for translate ES6 syntax to common.js syntax
Solution 3:[3]
If you want to include a structure you have built, you need to use import. If you want to export a structure that you have edited, you need to use export.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | ozanorkun |
Solution 3 | Cem Nisan |