Unable to deploy Astro application due to npm build error

Hello,

I am trying to deploy a repository from CF pages using the Astro framework but for some to me unknown reason it is unable to successfully build the application whenever I try to deploy it.

I carefully read the instruction from the CF framework guide (deploy-an-astro-site);
developers.cloudflare.com/pages/framework-guides/deploy-an-astro-site

And followed the instructions from the AstroDocs (@astrojs/cloudflare);
docs.astro.build/en/guides/integrations-guide/cloudflare

Also when I run the application locally there seems to be no issue.

But whenever I try to deploy it from the CF pages I get the following error;

 β€£ Cloning repository...
 β€£ warning: redirecting to https://gitlab.com/β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘/β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘.git/
 β€£ From https://gitlab.com/β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘/β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘
 β€£ * branch            β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ -> FETCH_HEAD
 β€£ 
 β€£ HEAD is now at β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ Initial Commit
 β€£ 
 β€£ 
 β€£ Success: Finished cloning repository files
 β€£ Detected the following tools from environment: 
 β€£ Executing user command: npm run build
 β€£ npm ERR! code ENOENT
 β€£ npm ERR! syscall open
 β€£ npm ERR! path /opt/buildhome/repo/package.json
 β€£ npm ERR! errno -2
 β€£ npm ERR! enoent ENOENT: no such file or directory, open '/opt/buildhome/repo/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: /opt/buildhome/.npm/_logs/debug.log
 β€£ Failed: Error while executing user command. Exited with error code: 254
 β€£ Failed: build command exited with code: 1
 β€£ Failed: error occurred while running build command

It also seems that whenever I select a specific framework preset for the application either by creating a new application or through the settings Β» build & deployments Β» build configurations Β» framework preset [Astro] and try to save it, it immediately jumps back to [None].

Any suggestions?

It looks like you don’t have a package.json

Did you not commit it?

Yes, I’ve commited the package.json file;

{
  "name": "astr0",
  "type": "module",
  "version": "0.0.1",
  "scripts": {
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro check && astro build",
    "preview": "astro preview",
    "astro": "astro"
  },
  "dependencies": {
    "@astrojs/check": "^0.3.1",
    "astro": "^3.6.0",
    "typescript": "^5.3.2"
  }
}

Is your repo public so we can take a look?

If not, where is it within the repo? npm is looking at the root and not seeing it

2 Likes

Ahh okay yes, that fixed the problem, I was running it from the wrong root directory…

Thank you mate! :pray:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.