cloudfoundry / nodejs-buildpack

Cloud Foundry buildpack for Node.js
http://docs.cloudfoundry.org/buildpacks/
Apache License 2.0
173 stars 385 forks source link

Local dependencies not being resolved npm 5.6.0. #163

Closed beku8 closed 6 years ago

beku8 commented 6 years ago

What version of Cloud Foundry and CF CLI are you using? (i.e. What is the output of running cf curl /v2/info && cf version?

{
   "name": "",
   "build": "",
   "support": "https://support.run.pivotal.io",
   "version": 0,
   "description": "Cloud Foundry sponsored by Pivotal",
   "authorization_endpoint": "https://login.run.pivotal.io",
   "token_endpoint": "https://uaa.run.pivotal.io",
   "min_cli_version": "6.22.0",
   "min_recommended_cli_version": "latest",
   "app_ssh_endpoint": "ssh.run.pivotal.io:2222",
   "app_ssh_host_key_fingerprint": "e7:13:4e:32:ee:39:62:df:54:41:d7:f7:8b:b2:a7:6b",
   "app_ssh_oauth_client": "ssh-proxy",
   "doppler_logging_endpoint": "wss://doppler.run.pivotal.io:443",
   "api_version": "2.123.0",
   "osbapi_version": "2.14",
   "routing_endpoint": "https://api.run.pivotal.io/routing"
}

cf version 6.38.0+7ddf0aadd.2018-08-07

What version of the buildpack you are using?

1.6.33

If you were attempting to accomplish a task, what was it you were attempting to do?

Trying to push an app depends on a local package. (e.g dep: file:../foo).

Update:

Just found out it was not working properly with npm version 5.6.0

Can you provide a sample app?

https://github.com/beku8/local-package-demo

Please confirm where necessary: [* ] I have included a log output

Waiting for API to complete processing files...

Staging app and tracing logs...
   -----> Download go 1.9.1
   -----> Running go build supply
   -----> Nodejs Buildpack version 1.6.33
   -----> Installing binaries
          engines.node (package.json): 8.11.4
          engines.npm (package.json): 5.6.0
   -----> Installing node 8.11.4
          Download [https://buildpacks.cloudfoundry.org/dependencies/node/node-8.11.4-linux-x64-cflinuxfs2-f03d0cbe.tgz]
          npm 5.6.0 already installed with node
   -----> Installing yarn 1.10.1
          Copy [/tmp/cache/final/dependencies/8f7725ada711249e2b350e073f5e426ac8ca834ec6e72f6921debab9d4bca1fd/yarn-1.10.1-any-stack-97bf147c.tar.gz]
          Installed yarn 1.10.1
   -----> Creating runtime environment
          NODE_ENV=production
          NODE_HOME=/tmp/contents751833268/deps/0/node
          NODE_MODULES_CACHE=true
          NODE_VERBOSE=false
          NPM_CONFIG_LOGLEVEL=error
          NPM_CONFIG_PRODUCTION=true
   -----> Building dependencies
          Prebuild detected (node_modules already exists)
          Rebuilding any native modules
   express@4.16.4 /tmp/app/node_modules/express
   accepts@1.3.5 /tmp/app/node_modules/accepts
   mime-types@2.1.20 /tmp/app/node_modules/mime-types
   mime-db@1.36.0 /tmp/app/node_modules/mime-db
   negotiator@0.6.1 /tmp/app/node_modules/negotiator
   array-flatten@1.1.1 /tmp/app/node_modules/array-flatten
   body-parser@1.18.3 /tmp/app/node_modules/body-parser
   bytes@3.0.0 /tmp/app/node_modules/bytes
   content-type@1.0.4 /tmp/app/node_modules/content-type
   debug@2.6.9 /tmp/app/node_modules/debug
   ms@2.0.0 /tmp/app/node_modules/ms
   depd@1.1.2 /tmp/app/node_modules/depd
   http-errors@1.6.3 /tmp/app/node_modules/http-errors
   inherits@2.0.3 /tmp/app/node_modules/inherits
   setprototypeof@1.1.0 /tmp/app/node_modules/setprototypeof
   statuses@1.4.0 /tmp/app/node_modules/statuses
   iconv-lite@0.4.23 /tmp/app/node_modules/iconv-lite
   safer-buffer@2.1.2 /tmp/app/node_modules/safer-buffer
   on-finished@2.3.0 /tmp/app/node_modules/on-finished
   ee-first@1.1.1 /tmp/app/node_modules/ee-first
   qs@6.5.2 /tmp/app/node_modules/qs
   raw-body@2.3.3 /tmp/app/node_modules/raw-body
   unpipe@1.0.0 /tmp/app/node_modules/unpipe
   type-is@1.6.16 /tmp/app/node_modules/type-is
   media-typer@0.3.0 /tmp/app/node_modules/media-typer
   content-disposition@0.5.2 /tmp/app/node_modules/content-disposition
   cookie@0.3.1 /tmp/app/node_modules/cookie
   cookie-signature@1.0.6 /tmp/app/node_modules/cookie-signature
   encodeurl@1.0.2 /tmp/app/node_modules/encodeurl
   escape-html@1.0.3 /tmp/app/node_modules/escape-html
   etag@1.8.1 /tmp/app/node_modules/etag
   finalhandler@1.1.1 /tmp/app/node_modules/finalhandler
   parseurl@1.3.2 /tmp/app/node_modules/parseurl
   fresh@0.5.2 /tmp/app/node_modules/fresh
   merge-descriptors@1.0.1 /tmp/app/node_modules/merge-descriptors
   methods@1.1.2 /tmp/app/node_modules/methods
   path-to-regexp@0.1.7 /tmp/app/node_modules/path-to-regexp
   proxy-addr@2.0.4 /tmp/app/node_modules/proxy-addr
   forwarded@0.1.2 /tmp/app/node_modules/forwarded
   ipaddr.js@1.8.0 /tmp/app/node_modules/ipaddr.js
   range-parser@1.2.0 /tmp/app/node_modules/range-parser
   safe-buffer@5.1.2 /tmp/app/node_modules/safe-buffer
   send@0.16.2 /tmp/app/node_modules/send
   destroy@1.0.4 /tmp/app/node_modules/destroy
   mime@1.4.1 /tmp/app/node_modules/mime
   serve-static@1.13.2 /tmp/app/node_modules/serve-static
   utils-merge@1.0.1 /tmp/app/node_modules/utils-merge
   vary@1.1.2 /tmp/app/node_modules/vary
          Installing any new modules (package.json + package-lock.json)
   npm ERR! code ENOLOCAL
   npm ERR! Could not install from "../../lib/dep1" as it does not contain a package.json file.
   npm ERR! A complete log of this run can be found in:
   npm ERR!     /home/vcap/.npm/_logs/2018-10-17T05_45_48_464Z-debug.log
          **ERROR** Unable to build dependencies: exit status 1
   Failed to compile droplet: Failed to run all supply scripts: exit status 14
   Exit status 223
   Cell 9434eb8f-e05d-4cda-8ee0-0c6a480f17b0 stopping instance 81bc3cbd-938a-45b4-954a-b64c03be19f5
   Cell 9434eb8f-e05d-4cda-8ee0-0c6a480f17b0 destroying container for instance 81bc3cbd-938a-45b4-954a-b64c03be19f5
Error staging application: App staging failed in the buildpack compile phase

[* ] I have included steps for reproduction

clone the repo &

$ cd apps/app1/
$ npm install
$ cf push lpd -c "npm start" -b https://github.com/cloudfoundry/nodejs-buildpack
cf-gitbot commented 6 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/161274214

The labels on this github issue will be updated when the story is started.

Ben16 commented 6 years ago

Hi @beku8,

Thank you for the fixture and detailed steps to reproduce the error. This error stems from the fact that cf push is run from the app1 dir, but your app attempts to reference a dependency outside of this directory (specifically ../../lib/dep1).

To fix this, we recommend:

Before pushing or running npm install, copy any local deps into your app directory (i.e. lib into app1) and update the reference in your package.json and package-lock.json accordingly. We modified your sample app locally in this way and successfully pushed. You could likely leverage an npm script to do this for you:

package.json

{
  ...
  "scripts": {
    ...
    "deploy": "cp -r ../../lib ./lib && npm install && cf push lpd -b https://github.com/cloudfoundry/nodejs-buildpack",
    ...
  },
  ...
  "dependencies": {
    "dep1": "file:./lib/dep1",
    ...
  },
  ...
}

package-lock.json

{
  ...
  "dependencies": {
    ...
    "dep1": {
      "version": "file:lib/dep1"
    },
    ...
  }
}

Then you can run:

$ npm run deploy

Hope that helps you! Since this is an issue related to the project structure, not CF itself, we'll go ahead and close this. That said, feel free to re-open if you're still seeing issues.

beku8 commented 6 years ago

@Ben16 Thanks! Your answer did solve our problem