cli: Bug: deploy command regression

The netlify deploy command used to deploy one of my sites has stopped working in netlify-cli@2.48.0

The command netlify deploy fails with a “Base directory does not exist” error.

> netlify deploy -p --dir public

Base directory does not exist: /Users/davidwells/David/analytics-project/analytics/site/main/site

Was something changed recently with the netlify deploy command?

This is the site in question: https://github.com/DavidWells/analytics/tree/master/site/main and the previously working deploy script is here: https://github.com/DavidWells/analytics/blob/master/site/main/package.json#L14

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 36 (29 by maintainers)

Commits related to this issue

Most upvoted comments

netlify dev is now working for me on netlify-cli@2.57.0.

No need to add a temporary base property to my netlify.toml anymore.

Thanks! 👍

@ehmicky Rad! This fix worked for me. Thanks for the quick response!

Seems that the fix to this broke things with my config, when using my monorepo setup. I recently updated past 2.56.0 (2.54.0 -> 2.59.1)

I feel like I could work around this but I would expect that the CLI would respect the the current working directory, unless I tell the CLI otherwise with dir.

Directory Structure

> <root>/
  > node_modules/
  > portal-partner/   # Command is run in this directory
    > dist/
    > netlify.toml
    > package.json
  > package.json

Debug output

> ../node_modules/.bin/netlify "deploy" "--debug"

​
❯ Initial build environment
cwd: <reporoot>/portal-partner
mode: cli
siteId: d8e0dab1-504b-43b5-950e-102d920c0475
​
❯ UI build settings
build:
  base: portal-partner
​
❯ Resolved build environment
branch: master
buildDir: <reporoot>/portal-partner
configPath: <reporoot>/portal-partner/netlify.toml
context: production
​
❯ Resolved config
build:
  base: <reporoot>/portal-partner
  publish: <reporoot>/dist
redirects:
  - from: /*
    status: 200
    to: /index.html
Deploy path:        <reporoot>/dist
Configuration path: <reporoot>/portal-partner/netlify.toml
    Error: ENOENT: no such file or directory, stat '<reporoot>/dist'
    Code: ENOENT

In my case publish and deploy path should be <reporoot>/portal-partner/dist.

Versions

> netlify-config --version
2.1.0
> netlify --version
netlify-cli/2.59.1 linux-x64 node-v14.3.0

Config

[build]
  publish = "dist"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

The following change makes things work, but seems incorrect given other third party tools work correctly within our mono repo setup:

 [build]
-  publish = "dist"
+  publish = "portal-partner/dist"
 
 [[redirects]]

Ran into another example of this.

  • With latest CLI, build fails with Base directory does not exist: /Users/xyz/site/frontend/site error
  • After reverting to netlify-cli@2.40.0 the deployment proceeds.

These are the logs:

  site git:(master) ✗ npm run deploy

  > abc-site@0.1.0 deploy /Users/xyz/site
  > netlify deploy --prod --dir out

  Base directory does not exist: /Users/xyz/site/frontend/site
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! abc-site@0.1.0 deploy: `netlify deploy --prod --dir out`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the abc-site@0.1.0 deploy script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

  npm ERR! A complete log of this run can be found in:
  npm ERR!     /Users/davidwells/.npm/_logs/2020-06-27T02_18_38_177Z-debug.log
  ➜  site git:(master) ✗ npm i netlify-cli@2.40.0 --save-dev

  > netlify-cli@2.40.0 postinstall /Users/xyz/site/node_modules/netlify-cli
  > node ./scripts/postinstall.js


  Success! Netlify CLI has been installed!

  Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.

  Next steps:

    netlify init     Connect or create a Netlify site from current directory
    netlify deploy   Deploy the latest changes to your Netlify site

  For more information on the CLI run netlify help
  Or visit the docs at https://cli.netlify.com

  + netlify-cli@2.40.0
  added 34 packages from 17 contributors, removed 49 packages, updated 20 packages, moved 11 packages and audited 2033 packages in 26.379s
  found 1 moderate severity vulnerability
    run `npm audit fix` to fix them, or `npm audit` for details
  ➜  site git:(master) ✗ npm run deploy

  > abc-site@0.1.0 deploy /Users/xyz/site
  > netlify deploy --prod --dir out

  Deploy path:        /Users/xyz/site/out
  Functions path:     /Users/xyz/site/functions
  Configuration path: /Users/xyz/site/netlify.toml
  Deploying to live site URL...
  ✔ Finished hashing 39 files and 1 functions
  ✔ CDN requesting 16 files and 1 functions
  ✔ Finished uploading 17 assets
  ✔ Deploy is live!

  Logs:              https://app.netlify.com/sites/xyz/deploys/123123
  Unique Deploy URL: https://12312312323--xyz-site.netlify.app
  Live URL:          https://xyz-site.netlify.app

I have added the following issues for the CLI flags problems mentioned above since those are separate from this issue’s problem:

https://github.com/netlify/build/pull/1581 is merged and released to npm.

@erezrokah Would it be possible for you to test https://github.com/netlify/cli/pull/953 and see whether the problem that you reproduced is now fixed?

First part (@netlify/config base behavior) done in https://github.com/netlify/build/pull/1581 Second and last part done by re-writing https://github.com/netlify/cli/pull/953

I am now trying to connect both PRs to see if this works.

We just discussed with @erezrokah and went with the following solution, which should solve this bug:

  • In @netlify/config, if cwd is a subdirectory of repositoryRoot, tries to find if any directory (that is >= cwd && < repositoryRoot in the tree structure) that has a .netlify or netlify.toml. If one exists, this is used as build.base, regardless of what base is set in UI build settings.
  • Since build.base is used to compute buildDir, @netlify/cli can now use the buildDir returned by @netlify/config as its projectDir/projectRoot/site.root which is used to find .netlify/state.json and resolve publish, functions, .env, _headers, _redirects, etc.
  • Do not pass any repositoryRoot flag from @netlify/cli to @netlify/config. Instead, let @netlify/config compute it by looking up .git from cwd

For the CLI flags (--dir, --functions, --site, --alias), I still think those should be fixed to re-use the logic from @netlify/config. They currently do not account for many use cases (properties case-insensitivity, contexts, etc.). We can create separate issues/bugs for each of those, separately from this issue though.

@ehmicky that’s is a great analysis and there is some work to be done on consolidation. We would first need to map out different use cases and make sure they are covered by tests.

To be more focused on this issue with the base directory - I would expect that when running from the CLI we would always ignore the UI/config settings for base and resolve the build directory using the current working directory.

More specifically running netlify deploy --prod --dir out should work when invoked from repo/site and netlify deploy --prod --dir site/out should work from invoked from repo (in the latter the CLI should not ask to link to a site if site/.netlify exists).

That should work for multiple sites under the same repo as well (e.g. netlify deploy --prod --dir site1/out, netlify deploy --prod --dir site2/out).