Open ehmicky opened 4 years ago
It seems like the only place retrieving state.json
is here:
So, it looks like the situation above would happen for any user who has a ~/.netlify/state.json
file on their machine, but no ./.netlify/state.json
(e.g. when creating a new Site directory). The question would then become: how did @biilmann end up having a ~/.netlify/state.json
file? Maybe he ran some netlify
CLI commands with the home directory being the current directory: based on the logic above, the current directory is the default value, so maybe that command created it?
@erezrokah What are your thoughts on this issue?
Thanks @ehmicky for looking into it.
I think it would make sense to ignore the home directory when looking for state.json
.
I don't think it is a valid use case to have a site in the home directory, WDYT?
Yes, I agree.
When a user is running a netlify
CLI command and cwd
is the home directory, what should happen?
The current code is assuming that there is always a valid .netlify/state.json
that can be read/written for any netlify
CLI command invocation.
Several possible solutions:
.netlify/state.json
is about to be written to, and the current directory is the home directory. This seems to happen only with the npm init
and npm link
commands.state.json
for the duration of the commandWhat do you think?
We can divide the logic:
Once I created a new site via a globally installed netlify-cli. ~/.netlify/state.json
was generated silently; I was not aware of that.
Later, I found that one of my tests was failing locally. This time, netlify-cli was installed via the project's package.json
.
Comparing --debug
output from local vs CI showed me this:
baseRelDir
was different. This led to the edge_functions
path being incorrect.
Somehow, I was able to guess that I needed to remove ~/.netlify/state.json
. It was very confusing 😅
This was initially reported by @biilmann.
He created a completely fresh project with just a
public
folder, afunctions
folder and anetlify.toml
file and then did anetlify deploy --prod
and instead of creating a new site or prompting for an existing one, it deployed to the last project he worked on and overwrote the product deploy there. It seems the CLI is writing the sitestate.json
to the.netlify
folder in my home directory instead of in the site specific directory.He is not sure how he got into that state because it is so hard to debug. For some reason, setting up a project ended up writing to his home directory instead of the project dir, and then any new project travels up and finds that state file.
Once he deleted that file things go back to working as expected.