Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
Node cannot find shared module in Yarn workspaces

I'm attempting to set up a monorepo for a full-stack project using Node.js + Express on the backend and a React app frontend (with CRA).

I've so far set up Yarn workspaces with the following directory structure:

monorepo
  – package.json
  – packages
      – server
        – package.json
      – frontend
        – package.json
      – shared
        – package.json

I then do yarn workspace frontend add shared and yarn workspace server add shared and successfully find that the shared package is listed as a workspace dependency for server and frontend in yarn list

Furthermore, I am able to find the shared package inside of the node_modules of each of the workspaces.

The weird thing is, the frontend app is able to see the module fine when doing

import { foo } from "shared"

but the backend app is throwing the following error (with the exact same import statement as above):

Error: Cannot find module 'shared'
Require stack:
- /usr/src/app/dist/src/getApp.js
- /usr/src/app/dist/src/index.js

I have a suspicion that for some reason the backend app is not looking inside of node_modules for this package based on the require stack. I've tried various ways of modifying the import statement but continue to get the same error.

What's even stranger is that when running ts-node or node directly inside of the server directory, I'm able to import the module perfectly fine. It is only when I run the server app with node dist/src/index.js that it fails to find the dependency.

I have confirmed that the package.json file in the shared package is properly pointing to the right files for main and types and made sure that the dependent projects have references in their tsconfig.json.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda