skip to Main Content

I am using node.js v18.17.0
I have set in package.json that "type": "module"

I use import http from 'http' which doesn’t give me any error
However, if I try to use export like:

function renderStatus(url){
    var arr = ["/home", "/list"]
    return arr.includes(url)?200:404

}

export renderStatus

It gives me the following error:

SyntaxError: Unexpected token 'export'

Can anyone explain why this is happening?
Thanks a lot!

2

Answers


  1. As Being Shame said, export {renderStatus} should be the correct syntax.
    We can also export function renderStatus(url){...} to export a function.

    Read more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

    Login or Signup to reply.
  2. Use Can Fix It By Either Of These;

    1. use export default renderStatus (if this is the only export from the concerning file)
    2. use export { renderStatus, export2, export3....} (in case of multiple exports from the concerning file)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search