Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
Cannot import router from file with ES6 import/export?

I am converting my whole node app to use the ES6 syntax import NME from "./file"

In my app.js file I am trying to import my routers but am getting the error "Cannot find module '/Users/app/git/app-node-api/src/routers/availability' imported from /Users/app/git/app-node-api/src/app.js"

This was working perfectly fine before using the require statements but since I am new to using the import for modules, something has messed up.

Why is this not working? I tried different export syntax's like export { router } but it didn't work?

My current import/export from files looks like below...

APP.JS

import express from "express"
import("./db/mongoose")
const app = express()

import availabilityRouter from "./routers/availability"
// ^ CANNOT FIND MODULE "/Users/app/git/app-node-api/src/routers/availability" ?

module.exports = app 

AVAILABILITY.JS

import express from "express"
const router = new express.Router()

router.get(`/verify/email/:email`, async (req, res) => {
  // DO STUFF
})

router.get(`/verify/username/:username`, async (req, res) => {
  // DO STUFF
})

module.exports = router // AM I EXPORTING CORRECTLY??

PACKAGE.JSON

{
  "name": "app-api",
  "version": "1.0.0",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "nodemon src/index.js",
    "dev": "env-cmd -f ./config/dev.env nodemon src/index.js -e js,hbs",
    "prod": "env-cmd -f ./config/prod.env nodemon src/index.js",
    "test": "env-cmd -f ./config/test.env nodemon --exec 'mocha -R min'",
    "deploy": "make this auto deploy code to ec2 instance"
  },
  "license": "ISC",
  "dependencies": {
   ////
}
}

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

module.exports commonjs syntax.

try this for ES6

export default router;
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!