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

122
Views
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
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!