Error: Cannot find module '/opt/render/project/dist/src/index.js'

Hi there,

First time posting and new here. Thanks in advance for helping me out.

I’m running into the following after my start command runs (this is a nodejs project):

==> Running 'node ../dist/src/index.js'

Dec 17 04:17:02 PMnode:internal/modules/cjs/loader:1147

Dec 17 04:17:02 PM throw err;

Dec 17 04:17:02 PM ^

Dec 17 04:17:02 PM

Dec 17 04:17:02 PMError: Cannot find module '/opt/render/project/dist/src/index.js'

Dec 17 04:17:02 PM at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)

Dec 17 04:17:02 PM at Module._load (node:internal/modules/cjs/loader:985:27)

Dec 17 04:17:02 PM at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)

Dec 17 04:17:02 PM at node:internal/main/run_main_module:28:49 {

Dec 17 04:17:02 PM code: 'MODULE_NOT_FOUND',

Dec 17 04:17:02 PM requireStack: []

Dec 17 04:17:02 PM}

In my settings, I have the following:

  • Root directory: blank
  • Build command: npm install && npm run build
  • Start command: node …/dist/src/index.js

My project is written in typescript, and my npm run build command is just (“build”: “tsc”), and creates a dist/ folder under my root directory.

This all works locally, so I’m unsure what might be happening. The index.js file does exist after running the build command.

Please let me know if I can clarify anything or provide more info.

Thanks again

Hi,

Your code will be pulled into /opt/render/project/src/.

Your start command is traversing out of that folder: /opt/render/project/dist/src/index.js

Maybe try removing the ../ from the start command.

Kind regards

Alan

Hi Alan,

Thanks for your suggestion.

I tried updating the start command to: dist/src/index.js but unfortunately ran into a similar error, but with a change to the path: ie Error: Cannot find module '/opt/render/project/src/dist/src/index.js' rather than Error: Cannot find module '/opt/render/project/dist/src/index.js'.

When I run my npm run build command (which is just “build”: “tsc”), my dist folder is nested directly under my project, not under project/src, so while I understand the error, maybe I’m not understanding what you mean by

Your code will be pulled into /opt/render/project/src/

Here’s an example of my file structure if that is helpful.

project-root
|-- dist
|   `-- src
|       `-- index.js
|-- src
|   `-- index.ts
`-- package.json

Thanks again for your time,
Fabian

If you’re seeing…

Error: Cannot find module '/opt/render/project/src/dist/src/index.js'

…the files aren’t where your structure diagram shows them. You can ignore the /opt/render/project/src part of the path. That is controlled by Render and is where your repo is cloned into.

So within your file structure dist/src/index.js isn’t being found. Either the path is incorrect, or maybe the built files have a different casing. Render uses Linux with a case-sensitive filesystem, so filepaths need to match the case exactly.

You could maybe debug it with a simple temporary addition to your Build Command, e.g.:

<your current build command> && ls dist

Which will list the structure of your dist folder into the deploy logs, or fail if it’s not there.

Alan

Hi Alan,

Your suggestion to update my build command to check what was in dist really helped. Turns out there wasn’t a src folder nested under dist.

Thanks again for the help!

Regards,
Fabian

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.