This has been working since forever, but a couple of days ago, I did a change to my app, I triggered a deploy and the file is not being created anymore, and the log shows that it was succesfully created with the correct variables printed in the log.
I tested by uploading the default config.json file which points to localhost and I get deployed the localhost version, I also tried deleting the file from the repo to see if it was being overwritten and nothing, the file is simply not being created. I haven’t changed anything in a long time so probably something changed in netlify that I’m not aware of.
I checked a couple of changelogs but I can’t find anything specific to my case and I’m not even sure if that is the case.
I apologize in advance if this is something well known by everyone.
First of all, welcome to the forum! Sounds like a great Build Plugin and sorry to hear that it stopped working.
To make sure I understand, you say:
the file is not being created anymore, and the log shows that it was succesfully created with the correct variables printed in the log.
So the plugin seems to be logging the right vars (console.log('Vars to write', JSON.stringify(environment));) but then does not write the file and does not throw any errors? Does this result in your build failing, or how do you know the file wasn’t actually written?
Last request: could you please share your Netlify URL so we can take a look?
You’re right, it logs the values but it doesn’t write the file at all and I know because the default one, the one I use for development is being deployed (pointing to localhost). And no, it doesn’t fail at all nor threw warnings/errors.
I tried locally with Netlify CLI and I did get a few errors there that I thought at first would be the cause but they weren’t. The CLI threw these:
As you can see in the code I posted initally, the catch block has error in the parenthesis and err in the block inside catch. It reached the catch block because the paths aren’t the same locally, so it wasn’t able to write the file. This wasn’t the cause.
Then it suggested the following
Plugin error: since "onSuccess" happens after deploy, the build has already succeeded and cannot fail anymore. This plugin should either:
- use utils.build.failPlugin() instead of utils.build.failBuild() to clarify that the plugin failed, but not the build.
- use "onPostBuild" instead of "onSuccess" if the plugin failure should make the build fail too. Please note that "onPostBuild" (unlike "onSuccess") happens before deploy.
In this case I changed to failPlugin.
I fixed these locally and it worked (I had to fix some path issues locally but had to undo them when I uploaded the plugin fixed), I saw that the config file was written.
That’s all I can say about this. Debugging it it’s a little bit complicated and I have no more info to share (I think).
Thanks again for answering. If you need more info, let me know.