Node.js Module Resolution Issue with Yarn Workspace Monorepo Deployment
crinklepackage
HOBBYOP

2 years ago

I'm deploying a Node.js monorepo using Yarn workspaces on Railway, but I'm facing persistent module resolution issues despite trying multiple approaches.

The error:

Error: Cannot find module '/app/packages/server/api/node_modules/@wavenotes-new/shared/dist/index.js'. Please verify that the package.json has a valid "main" entry
  code: 'MODULE_NOT_FOUND',
  path: '/app/packages/server/api/node_modules/@wavenotes-new/shared/package.json',
  requestPath: '@wavenotes-new/shared'

My setup:

Monorepo with Yarn 4 workspaces

.railway.toml configuration

Custom nixpacks.toml configuration

Services: API and Worker

What I've tried:

  • Explicitly copying the shared package to node_modules during build
  • Setting the correct main entry in package.json
  • Creating global node_modules links
  • Setting NODE_PATH environment variable
  • Different copying approaches (cp -r vs cp -rf)
  • Verifying the dist files exist in various locations
  • Adding verification steps in the build process
  • Despite all these approaches and verification steps showing that the files exist in the correct locations during build time, at runtime Node.js still can't find the module.

My specific questions:

  • What's the recommended approach for handling internal workspace packages in Railway deployments?
  • Is there a configuration setting I'm missing for monorepo deployments?
  • Could there be something happening between the build and runtime phases that's affecting module resolution?
  • Are there specific debug logs/commands I can use to better diagnose this issue?

Any insights would be greatly appreciated, as I've spent significant time trying to resolve this.

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

Closed

1 Replies

2 years ago

Hello,

Looks like you have made significant progress, but unfortunately we aren't able to help here due to the errors you are getting -

src/server/types/index.ts(13,1): error TS2308: Module './entities' has already exported a member named 'PodcastRecord'. Consider explicitly re-exporting to resolve the ambiguity.

This error wouldn't pertain to the Railway platform or product, perhaps stack overflow can help you further here.

Best,

Brody


Status changed to Closed brody • over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...