CICD Pipeline error finding package.json

1

Hi team,

I'm trying to do a CICD pipeline with CDK code for AWS infra,

In my code commit repository, I have a parent folder that contains 2 subdirectories one for my spring boot app and the second for the type script CDK project,

when I created the pipeline with CDK I did cd my-cdk-project

const myrepository = codecommit.Repository.fromRepositoryName(
      this,
      "myrepository",
      "my-repository-name"
    );
const pipeline = new pipelines.CodePipeline(this, "Pipeline", {
      crossAccountKeys: true,
      pipelineName: "cdk-pipeline",
      synth: new pipelines.CodeBuildStep("Synth", {
        buildEnvironment: { privileged: true },
        input: pipelines.CodePipelineSource.codeCommit(
          myrepository,
          "mybranchname"
        ),
        commands: [
          "cd my-cdk-project",
          "npm ci",
          "npm run build",
          "npx cdk synth",
        ],
        primaryOutputDirectory: "my-cdk-project/cdk.out",
      }),
    });

but when the pipeline execute I have the impression that it ignore all commands before the npm ci, so I have this error

I tried to do cd ./my-cdk-project, but still have the same error

I also tried with pipelines.ShellStep... but the error is still the same :

I recommit the package-lock.json but this did not solve the issue

Running command npm ci
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /codebuild/output/src123456789/src/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/codebuild/output/src123456789/src/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/xfdgjgfghghjghg-debug.log

did I miss something?

Thank you for your help!

3 Answers
0
Accepted Answer

I fixed it by redeploying the CDK pipeline itself,

I was adding the cd mysubDir and pushing, and the pipeline ran upon push but doesn't seem to take into account my modif (cd mySubDir)

so I redeployed the CDK pipeline and it works, now the command cd mySubDir is executed.

Thank you

Jess
answered a year ago
profile picture
EXPERT
reviewed a month ago
0

Have you generated and committed your package.json file already? If that is not present, the npm ci command cannot run.

profile picture
rowanu
answered a year ago
0

Hello,

The code ENOENT means that npm fails to open a file or directory that’s required for executing the command.

I believe that mostly the package.json file is not committed to the CodeCommit Repo and now when CodeBuild Runs, it is not able to find the file.

One thing you can do is check your .gitignore file for package.json. Please note that if package.json is present in the .gitignore file then it will be ignored during the commit. So please remove package.json from the gitignore file if you find it.

If this doesn’t help then, please feel free to refer these third party links for more information:

[+] https://sebhastian.com/npm-err-enoent/

[+] https://www.codejourney.net/how-to-fix-npm-err-enoent-enoent-no-such-file-or-directory-rename/

[+] https://community.n8n.io/t/npm-not-able-to-find-file/2859

[+] https://you.com/search?q=this%20is%20related%20to%20npm%20not%20being%20able%20to%20find%20a%20file

AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions