getting an "Error: ENOENT: no such file or directory, scandir " in nodejs

62 views Asked by At

I'm trying to clone a nodejs project from github in a docker container, run and build it so i can upload build files to my amazon s3 bucket

executing npm run build creates a dist folder and i'm trying to get all the files inside it but not able to...

running npm rebuild node-sass would solve the problem if saas is enabled but that's not the case here

here is my Dockerfile

FROM ubuntu:focal

RUN apt-get update
RUN apt-get install -y curl

RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs

RUN apt-get install git -y

WORKDIR /home/app

COPY main.sh main.sh
COPY script.js script.js
COPY package*.json .

RUN npm install

# chmod +x --> gives permission to make main.sh and script.js executable
RUN chmod +x main.sh
RUN chmod +x script.js

ENTRYPOINT [ "/home/app/main.sh" ]

main.sh

#!/bin/bash

export GIT_REPOSITORY_URL="$GIT_REPOSITORY_URL"

git clone "$GIT_REPOSITORY_URL" /home/app/ouput

exec node script.js

script.js

const {exec} = require("child_process");
const path = require("path");
const fs = require("fs");

const s3Client = new S3Client({
    region: '',
    credentials : {
        accessKeyId: '',
        secretAccessKey: ''
    }
})

async function fun(){

    console.log("Executing script.js");
    const outDirPath = path.join(__dirname, 'output')
    const process = exec(`cd ${outDirPath} && npm install && npm run build && ls`);

    process.stdout.on('data', function(data) {
        console.log(data.toString());
    })

    process.stderr.on('error', function(data) {
        console.log('Error', data.toString());
    })

    process.on('close', async function(){
        console.log('Build Complete');

        const distFolderPath = path.join(__dirname, 'output', 'dist');
        const distFolderContents = fs.readdirSync(distFolderPath, {recursive: true});

        //...rest of the code
    })
}

fun();

it clones, runs and builds successfully but cant find the dist folder

0

There are 0 answers