Question

npm prepare on DO App Platform

My app depends on private npm packages hosted on GitHub Packages, so I have a script which generates my .npmrc before npm install.

package.json excerpt:

{
  "scripts": {
    "prepare": "npm run npmrc:create",
    "npmrc:create": "node scripts/create-npmrc"
  }
}

Here’s what npm install looks like locally:

$ npm i

> @{{org}}/{{app}}@0.0.0 prepare
> npm run npmrc:create


> @{{org}}/{{app}}@0.0.0 npmrc:create
> node scripts/create-npmrc


up to date, audited 1124 packages in 2s

106 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Here’s my build log:

=> Initializing build
=> Retrieving source code to /workspace
=> Checking out commit "{{hash}}"
=> Validating environment

=> Building app using buildpacks
=> Injecting app environment variables:
     GITHUB_TOKEN
=> Configuring custom build command to be run at the end of the build:
     npm run build
=> Running buildpack detection

heroku/nodejs-engine  0.5.0
digitalocean/node     0.2.0
digitalocean/procfile 0.0.3
digitalocean/custom   0.1.0


=> Building app

---> Node.js Buildpack
---> Installing toolbox
---> - jq
---> - yj
---> Getting Node version
---> Resolving Node version
---> Downloading and extracting Node v12.20.1
---> Parsing package.json
---> No file to start server
---> either use 'docker run' to start container or add index.js or server.js
Installing node_modules using npm (from package-lock.json)
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@{{org}}%2f{{lib}} - Not found
npm ERR! 404
npm ERR! 404  '@{{org}}/{{lib}}@0.1.1' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/apps/.npm/_logs/2021-01-16T22_53_11_554Z-debug.log
unable to invoke layer creator
installing node_modules: exit status 1
ERROR: failed to build: exit status 1
 ! Build failed (145)

It looks like prepare isn’t run when App Platform builds my app.

Related: https://www.digitalocean.com/community/questions/how-to-use-private-npm-packages-on-do-app-platform


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.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
January 18, 2021
Accepted Answer

👋🏼 @ptrkcsk

App Platform runs npm ci for npm versions 5.7.0 and above, and npm install for older versions. Looking through similar issues reported by NPM users, it seems like npm ci runs prepare/preinstall scripts differently than npm install especially around the ordering of these scripts and the registry auth checks.

As a workaround I would recommend committing an .npmrc file to your repo. You can store secrets or tokens in environment variables and reference them in .npmrc so you wouldn’t need to commit them to your repo. See: https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow#create-and-check-in-a-project-specific-npmrc-file

Let me know if that helps!

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.