I dont know how to fix Error: Cannot find module '/app/dist/index.js'

I imported a replit app to github and then onto here, but it doesnt want to work straight up. Im a complete noob and relied on replits AI to write the entire thing - but it works over there under preview but not here. Can anyone suggest how i fix this?

Replit tells me to run npm run build then npm run start but this happens:
$ npm run build
np

rest-express@1.0.0 build /app
vite build && tsc server/index.ts --outDir dist && cp -r server/public/* dist/public/

m /rbd/pnpm-volume/3a1658ed-9258-4edc-863c-aa700794475a/node_modules/.registry.npmjs.org/vite/5.4.14/node_modules/vite/bin/vite.js:2
import { performance } from ‘node:perf_hooks’
^

SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rest-express@1.0.0 build: vite build && tsc server/index.ts --outDir dist && cp -r server/public/* dist/public/
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rest-express@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npm-cache/10.24.1/_logs/2025-02-13T13_21_39_140Z-debug.log
r
app@celestial-ionized-dugout:~ 13:21
$ npm run start

rest-express@1.0.0 start /app
NODE_ENV=production node dist/index.js

internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module ‘/app/dist/index.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rest-express@1.0.0 start: NODE_ENV=production node dist/index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rest-express@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npm-cache/10.24.1/_logs/2025-02-13T13_21_42_562Z-debug.log

Thanks

Hello @Uchiharr welcome to the Glitch forum!

What’s happening here is that your project is failing the npm run build step - that step generates the dist/index.js file that npm run start can’t find.

I suspect the issue is that your Replit package.json file doesn’t include the directions to tell Gllitch what version of Node to run, and when that happens we fall back to a really old version: Node 10, which doesn’t understand some of the syntax you used on Replit.

You can try adding

“engines”:{
   “node”: “16.x”
}

to your package.json file - you could add that between the “scripts” section and the “dependencies” section. That version of Node should be able to understand the part that’s breaking right now (but there’s no guarantee something else won’t be unhappy with that version, and that’s the most recent one available on Glitch right now).

Let us know if that helps at all. Cheers!
cori

After changing this the project has been: Suspended for exceeding node_modules space

I dont seem to be able to recreate a project even a blank just spins endlessly

OK i got it back up and running again

I can now start to run the build but i get a million errors -
$ npm run build

rest-express@1.0.0 build
npm run build:server && npm run build:client

rest-express@1.0.0 build:server
tsc server/index.ts --outDir dist

server/index.ts:1:8 - error TS1259: Module ‘“/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/@types/express/index”’ can only be default-imported using the ‘esModuleInterop’ flag

1 import express, { type Request, Response, NextFunction } from “express”;
~~~~~~~

…/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/@types/express/index.d.ts:128:1
128 export = e;
~~~~~~~~~~~
This module is declared with ‘export =’, and can only be used with a default import when using the ‘esModuleInterop’ flag.

server/routes.ts:4:80 - error TS2307: Cannot find module ‘@shared/schema’ or its corresponding type declarations.

4 import { insertWorkoutSchema, insertExerciseSchema, insertHistorySchema } from “@shared/schema”;
~~~~~~~~~~~~~~~~

server/storage.ts:1:127 - error TS2307: Cannot find module ‘@shared/schema’ or its corresponding type declarations.

1 import { type Workout, type Exercise, type WorkoutHistory, type InsertWorkout, type InsertExercise, type InsertHistory } from “@shared/schema”;
~~~~~~~~~~~~~~~~

server/vite.ts:1:8 - error TS1259: Module ‘“/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/@types/express/index”’ can only be default-imported using the ‘esModuleInterop’ flag

1 import express, { type Express } from “express”;
~~~~~~~

…/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/@types/express/index.d.ts:128:1
128 export = e;
~~~~~~~~~~~
This module is declared with ‘export =’, and can only be used with a default import when using the ‘esModuleInterop’ flag.

server/vite.ts:2:8 - error TS1192: Module ‘“fs”’ has no default export.

2 import fs from “fs”;
~~

server/vite.ts:3:8 - error TS1259: Module ‘“path”’ can only be default-imported using the ‘esModuleInterop’ flag

3 import path, { dirname } from “path”;
~~~~

…/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/@types/node/path.d.ts:178:5
178 export = path;
~~~~~~~~~~~~~~
This module is declared with ‘export =’, and can only be used with a default import when using the ‘esModuleInterop’ flag.

server/vite.ts:6:34 - error TS1343: The ‘import.meta’ meta-property is only allowed when the ‘–module’ option is ‘es2020’, ‘es2022’, ‘esnext’, ‘system’, ‘node16’, or ‘nodenext’.

6 const __filename = fileURLToPath(import.meta.url);
~~~~~~~~~~~

server/vite.ts:7:41 - error TS1343: The ‘import.meta’ meta-property is only allowed when the ‘–module’ option is ‘es2020’, ‘es2022’, ‘esnext’, ‘system’, ‘node16’, or ‘nodenext’.

7 const __dirname = dirname(fileURLToPath(import.meta.url));
~~~~~~~~~~~

server/vite.ts:25:33 - error TS2300: Duplicate identifier ‘app’.

25 export async function setupVite(app: Express, server: Server) {
~~~

server/vite.ts:26:24 - error TS2304: Cannot find name ‘ServerOptions’.

26 const serverOptions: ServerOptions = {
~~~~~~~~~~~~~

server/vite.ts:34:9 - error TS2300: Duplicate identifier ‘app’.

34 const app = express();
~~~

vite.config.ts:4:8 - error TS1259: Module ‘“path”’ can only be default-imported using the ‘esModuleInterop’ flag

4 import path, { dirname } from “path”;
~~~~

…/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/@types/node/path.d.ts:178:5
178 export = path;
~~~~~~~~~~~~~~
This module is declared with ‘export =’, and can only be used with a default import when using the ‘esModuleInterop’ flag.

vite.config.ts:8:34 - error TS1343: The ‘import.meta’ meta-property is only allowed when the ‘–module’ option is ‘es2020’, ‘es2022’, ‘esnext’, ‘system’, ‘node16’, or ‘nodenext’.

8 const __filename = fileURLToPath(import.meta.url);
~~~~~~~~~~~

…/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/vite/dist/node/index.d.ts:5:41 - error TS2307: Cannot find module ‘rollup/parseAst’ or its corresponding type declarations.
There are types at ‘/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/rollup/dist/parseAst.d.ts’, but this result could not be resolved under your current ‘moduleResolution’ setting. Consider updating to ‘node16’, ‘nodenext’, or ‘bundler’.

5 export { parseAst, parseAstAsync } from ‘rollup/parseAst’;
~~~~~~~~~~~~~~~~~

Found 14 errors in 6 files.

Errors Files
1 server/index.ts:1
1 server/routes.ts:4
1 server/storage.ts:1
8 server/vite.ts:1
2 vite.config.ts:4
1 …/rbd/pnpm-volume/7e773d08-ec6d-4062-bb94-ecbc6656c540/node_modules/vite/dist/node/index.d.ts:5

A couple of different things going on in here, I think. One is that it seems likely that this project requires more node_modules space than we allow, which means the project probably isn’t suitable for Glitch. Also when i try to nvm install it locally I see errors mentioning that some of the package versions require Node 18 or greater - a different reason this project may not fit Glitch right now.

I’m not sure what you’re seeing with “blank” projects but i was just able to load the Editor for your other public project, but i see you got that one running at least a bit. Those errors seem to reinforce the idea that we might not have a version of Node that will work with your project, but you could try updating your tsconfig file with a compilerOption like "esModuleInterop": true.

My guess is that eventually you’ll run into Node version issues that can’t be resolved without downgrading some of your npm packages, and that may break some of your project’s features.