Auto generated files: to git or not to git?

I noticed in v4 a couple of folders and files being generated:

  • ./strapi/client/app.js
  • ./strapi/client/index.html

These files also have the comment:

This file was automatically generated by Strapi.
Any modifications made will be discarded.

I could not find a whole lot of information about these files (and what they are actually used for). They are not in de default .gitignore list but I cannot find if I should add them to vcs or not? Anyone knows?

I also noticed a components.d.ts and contentTypes.d.ts under /types/generated. I am not using Typescript for my strapi project so I do not know why strapi did generate those files anyway but the same question goes: should I put these in my git repo?

System Information
  • Strapi Version: 4.13.6
  • Operating System: MacOS latest
  • Database: postgresql@14
  • Node Version: v20.10.0
  • NPM Version: v10.2.5
  • Yarn Version: -

I think the files under types/generated are required, so they should be committed. If you modify e.g. an API schema (for example, you make a non-required field required in the admin interface), then these files will be updated.

I don’t know about the other files. I don’t think I have them, at least, not at that path. Maybe could you share what they contain?

It is quite simple to reproduce I found out, just create a new strapi v4 project, run npm run build and you will see the .strapi folder with files.

I did a little digging (emphasise on little). The files are used by the admin ui. Everytime you run npm run develop the files will be re-generated. I did not test what happens on a production environment.

Nevertheless I think I made a mistake. The .strapi folder IS in the .gitignore file. The initial project where I saw this, is in a migration path. The ignore file is not up to date as it seems. I am not sure if it is in the migration docs.

And about the typescript files, it seems (to me) that these files are required if you use strapi in typescript context, but what if you’re not?

*edit: I noticed that the types/generated folder is generated (its in the name) just like the .strapi folder: once you run npm run develop. It overwrites any changes made on later runs of npm run develop.

Right. I think the autogeneration of types should only be done if you have configured strapi to be a typescript project.

In fact, according to the documentation it should not automatically generate the type files, it autogeneration defaults to false (according to documentation). TypeScript configuration | Strapi Documentation.

I tried to set it to false manually via config/typescript.js and config/typescript.ts. It still generates the files. Seems like a bug to me.

I’ve opened a bug report for the typescript types generating on a javascript project: Typescript type autogeneration is done for non typescript projects · Issue #19195 · strapi/strapi · GitHub

A little update on the .strapi folder. That wasn’t in the .gitignore file after all when I first saw this. In fact, it was added to the v4.17.0 release (yesterday as of typing): chore(generator): add runtime dir to gitignore by joshuaellis · Pull Request #18978 · strapi/strapi · GitHub.

Right. I think the autogeneration of types should only be done if you have configured strapi to be a typescript project.

The idea behind generating types even for JavaScript projects is that it would allow Strapi types to propose better intellisense for common APIs (such as the entity service) even for regular JS code.

New JS Strapi projects are created with a jsconfig.json file which makes use of the generated types to check the project.

In fact, according to the documentation it should not automatically generate the type files, it autogeneration defaults to false (according to documentation). TypeScript configuration | Strapi Documentation.

The documentation has not been updated as it should have when we’ve removed the option. Sorry for this.

And about the typescript files, it seems (to me) that these files are required if you use strapi in typescript context, but what if you’re not?

Those are not required but we highly advise making use of them.

I tried to set it to false manually via config/typescript.js and config/typescript.ts . It still generates the files. Seems like a bug to me

We’re adding back the experimental autogenerate option for JavaScript projects only. It should be available in the next version

I think the files under types/generated are required, so they should be committed.

I tend to recommend committing them. The only issue that can arise from this is if you’re using the enterprise edition which can result in differences if the generation happens sometimes in CE and sometimes in EE

Hi @Convly, thanks for your detailed explanation, much appreciated!

I can follow most of your response. I am not sure about the committing part yet, perhaps I do not understand the typescript part well enough yet (I mainly focus on just Javascript to be honest). It seems that the content of the files get generated every time you run npm run develop, so what does it offer me to store those files to my vcs?

There might be benefits for production but I am not so sure about that so thats why I am asking.