Question

Functions deployment error: Unexpected token › in JSON at position 0

I am trying to deploy two Functions that are a component of an app in the App Platform. I keep getting this error:

[2023-09-22 22:33:41] │ Failures:
[2023-09-22 22:33:41] │  ›   Error: While deploying 'get-leaderboard-entries' (running remote build): 
[2023-09-22 22:33:41] │  ›   Unexpected token › in JSON at position 0
[2023-09-22 22:33:41] │  ›   Error: While deploying 'save-new-top-time' (running remote build): 
[2023-09-22 22:33:41] │  ›   Unexpected token › in JSON at position 0
[2023-09-22 22:33:42] │ 
[2023-09-22 22:33:42] │ command exited with code 1
[2023-09-22 22:33:42] │ 
[2023-09-22 22:33:42] │  ✘ build failed

I have cleared the top level directory of the Functions project so all that is left is:

  • /lib/
  • /packages/
  • /.gitignore
  • /project.yml

I have a build.sh under /lib/ and for both Functions under /packages/ . Each build.sh basically does

npm install
npm run build

All package.json and tsconfig.json files don’t seem to have any invalid syntax.

Running doctl sls deploy --remote-build works though.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Copied solution after some troubleshooting with Bobby:

I think I have pinpointed the problem. If there is a build.sh script in the lib folder and it doesn’t have execute permission, then the JSON error is shown in the build logs. After running

git add --chmod=+x -- build.sh

the build should either be able to finish or error out with code 126. If you get error code 126, then you’ll probably need to run the same command for the other build.sh scripts. Tried this command after searching around and found this.

Hi there,

What is the Node.js version that you are using on the App Platform?

The Default Buildpack Stack on the App Platform uses version 0.3.6 of the Node.js Cloud Native Buildpack by default. The buildpack supports Node.js runtime versions up to 17.x. If no version is specified in your app, App Platform defaults to using version 16.x.

Based on the error, I think that you might need at least Node.js 18.x. You can choose to build and deploy apps using the upcoming Ubuntu 22.04 stack by adding the specified app spec feature to the root of your app spec.

features:
    - buildpack-stack=ubuntu-22

That way you will be able to use the new Node.js version.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.