I am trying to run a Node.js TypeScript app on Cyclic.sh from a subdirectory in the repo and I am having trouble. There is nothing in their tutorials about both TypeScript and a subdirectory, so I am looking for some guidance here. My specs:
The repo
Cyclic (advanced) Build Options:
- Runtime:
Node 18.12.1 - Root Path:
/lol-pickem-api - Output Path:
lol-pickem-api/dist
/lol-pickem-api/package.json
"main": "server.js",
"scripts": {
"build": "tsc --build",
"build:watch": "tsc --watch",
"start": "node dist/server.js",
"start:watch": "rm -rf \"./dist/*\" && tsc-watch --onSuccess \"node -r source-map-support/register .\"",
"debug": "rm -rf \"./dist/*\" && tsc-watch --onSuccess \"node --inspect -r source-map-support/register .\""
},
/lol-pickem-api/tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"module": "commonjs",
"outDir": "./dist",
"baseUrl": "./src",
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["src/**/*.ts", "./package.json"],
"exclude": ["node_modules"]
}
The errors:
2023-07-18 16:40:31.061: node:internal/modules/cjs/loader:1031
throw err;
^
Error: Cannot find module '/var/task/dist/server.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
at Function.Module._load (node:internal/modules/cjs/loader:873:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
2023-07-18 16:40:31.076:
2023-07-18 16:40:31.076: ERROR: Failed to run "npm run start". Start script defined in package.json:
"scripts": {
"start": "node dist/server.js"
...
Exited with code: 1
2023-07-18 16:40:31.088: [CYCLIC] ERROR: No response from server on port 3000
2023-07-18 16:40:31.593: node:internal/modules/cjs/loader:1031
throw err;
^
Error: Cannot find module '/var/task/dist/server.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
at Function.Module._load (node:internal/modules/cjs/loader:873:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
ERROR: Failed to run "npm run start". Start script defined in package.json:
"scripts": {
"start": "node dist/server.js"
...
Exited with code: 1
2023-07-18 16:40:31.733: node:internal/modules/cjs/loader:1031
throw err;
^
Error: Cannot find module '/var/task/dist/server.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
at Function.Module._load (node:internal/modules/cjs/loader:873:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
2023-07-18 16:40:31.751:
2023-07-18 16:40:31.751: ERROR: Failed to run "npm run start". Start script defined in package.json:
"scripts": {
"start": "node dist/server.js"
...
2023-07-18 16:40:31.751: Exited with code: 1
2023-07-18 16:40:31.759: [CYCLIC] ERROR: No response from server on port 3000
Any and all help would be much appreciated!
Try
"start": "node src/server.js"directly (as if nodistsubfolder)While Cyclic docs may not be explicit about it, if you define an output path, the latter becomes the current working directory of your final app bundle. That is why that output path must also contain your
package.jsonfile.And another consequence is that all runtime file paths (in particular for the
startscript) are relative to that new cwd.Therefore in your case, after build you have:
With Output Path:
lol-pickem-api/dist, Cyclic bundles only that subdirectory, which becomes the cwd.When launching your app, Cyclic then finds the
package.jsonfile inside, with astartscript and executes it.The path is now relative to the cwd, hence
server.jsis insrcsubfolder. And you can just executenode src/server.js.Additionally, make sure your
node_modulesdependencies are also available within yourdistoutput path: as mentioned above, only that folder is bundled, so you need to have: