Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
Cannot find module express cors

I just clone my repository on my Ubunto 20.04 I have installed everything but I keep getting this error when I try to run the server. It works well on my windows machine.

Error: Cannot find module '../../Middlewares/AllowCors' Require stack:

  • /home/medvik/Documents/github/nextjs-ecom/ecomApi/routes/User/CreateUser.js
  • /home/medvik/Documents/github/nextjs-ecom/ecomApi/app.js
  • /home/medvik/Documents/github/nextjs-ecom/ecomApi/bin/www at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (/home/medvik/Documents/github/nextjs-ecom/ecomApi/routes/User/CreateUser.js:4:19) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { code: 'MODULE_NOT_FOUND',

The core middleware file path:/MiddleWare/AllowCors.js

const cors = require("cors");

const whitelist = [
  "http://localhost:8080", 
  "http://localhost:3000", 
];
var corsOptionsDelegate = (req, callback) => {
  var corsOptions;
  if (whitelist.indexOf(req.header("Origin")) !== -1) {
    corsOptions = { origin: true };
  } else {
    corsOptions = { origin: false };
  }
  callback(null, corsOptions);
};

exports.cors = cors();
exports.corsWithOptions = cors(corsOptionsDelegate);

My CreateUser file is in /router/User/CreateUser.js

const express = require("express");
const bcrypt = require("bcryptjs");
const joi = require("joi");
const allowCors = require("../../Middlewares/AllowCors");

router.route("/")
.options(allowCors.corsWithOptions, (req, res) => {
  res.sendStatus(200);
}).post(allowCors.corsWithOptions, async (req, res) => {
  try {}} catch (err) {
    console.log(err);
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem is with the file system Linux is is case sensitive unlike windows in my code, I had imported the cors middleware like this

const allowCors = require("../../Middlewares/AllowCors");

this works well in windows even tho the correct import should have been

const allowCors = require("../../MiddleWares/AllowCors");

since I named my middleware folder as MiddleWares.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda