I'm trying to convert my typescript files to javascript files on my github actions pipeline. I am using Node.js/Express.js with typescript.
Problem
The CI is stuck at step "install dependencies & convert typescript to javascript". It looks like it works since I can see the console.log() , but the CI will not finish. Why is that?
Here is my package.json:
npm run convert converts typescript to javascript files into the backend-build folder. The backend-build folder contains the js file after conversion. The backend-build folder is not tracked in the repository because they are compiled files from npm run convert (i.e an Artifact).
I run it whenever I start my server.
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "backend-build/index.js",
"scripts": {
"tsc": "tsc",
"convert:build": "tsc -w",
"convert:run": "nodemon backend-build/index.js",
"convert": "concurrently npm:convert:*",
"start": " node backend-build/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"concurrently": "^5.3.0"
},
"dependencies": {
"@types/cors": "^2.8.8",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.8",
"@types/pg": "^7.14.7",
"backblaze-b2": "^1.7.0",
"cors": "^2.8.5",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"multer": "^1.4.3",
"nodemon": "^2.0.6",
"pg": "^8.5.1",
"typescript": "^4.0.5"
}
}
Here is my typescript file (index.ts):
import express from "express";
import dotenv from "dotenv";
import cors from "cors";
if (process.env.NODE_ENV !== "production") {
dotenv.config();
}
const app = express();
// middleware for parsing bodies from URL
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors({ origin: true, credentials: true }));
console.log("NODE ENV", process.env.privateKey);
app.use("/api/test", (req, res) => {
res.send("hi");
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`App running on port ${port}.`);
});
Here is my main.yml for Github actions:
name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 #deploys to heroku
- uses: akhileshns/[email protected] # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "app" #Must be unique in Heroku
heroku_email: "a.com"
- name: install dependencies & convert typescript to javascript
run: |
npm install
npm run convert
Output of CI / the Problem (it is stuck at this step)
Run npm install
npm install
npm run convert
shell: /usr/bin/bash -e {0}
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
> [email protected] postinstall /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend/node_modules/nodemon
> node bin/postinstall || exit 0
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 294 packages from 222 contributors and audited 296 packages in 27.56s
22 packages are looking for funding
run `npm fund` for details
found 4 moderate severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
> [email protected] convert /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
> concurrently npm:convert:*
[convert:build]
[convert:build] > [email protected] convert:build /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
[convert:build] > tsc -w
[convert:build]
[convert:run]
[convert:run] > [email protected] convert:run /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
[convert:run] > nodemon backend-build/index.js
[convert:run]
[convert:run] [nodemon] 2.0.15
[convert:run] [nodemon] to restart at any time, enter `rs`
[convert:run] [nodemon] watching path(s): *.*
[convert:run] [nodemon] watching extensions: js,mjs,json
[convert:run] [nodemon] starting `node backend-build/index.js backend-build/index.js`
[convert:run] internal/modules/cjs/loader.js:905
[convert:run] throw err;
[convert:run] ^
[convert:run]
[convert:run] Error: Cannot find module '/home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend/backend-build/index.js'
[convert:run] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
[convert:run] at Function.Module._load (internal/modules/cjs/loader.js:746:27)
[convert:run] at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[convert:run] at internal/main/run_main_module.js:17:47 {
[convert:run] code: 'MODULE_NOT_FOUND',
[convert:run] requireStack: []
[convert:run] }
[convert:run] [nodemon] app crashed - waiting for file changes before starting...
[convert:build] c3:28:10 AM - Starting compilation in watch mode...
[convert:build]
[convert:build]
[convert:build] 3:28:12 AM - Found 0 errors. Watching for file changes.
[convert:run] [nodemon] restarting due to changes...
[convert:run] [nodemon] starting `node backend-build/index.js backend-build/index.js`
[convert:run] NODE ENV undefined
[convert:run] App running on port 5000.
Resource used: https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts
CodePudding user response:
The job is staying "open" because of the -w (watch) directive. You don't want to use watch on your CI jobs unless you're also doing something to kill the watched process.
The errors suggest that your paths aren't correct so it's trying to run tsc -w
, and then failing to find anything in the given path (./gh_actions_heroku_backend/gh_actions_heroku_backend
) and then staying "open" because of the watch directive.