Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strapi exits on fs.writeFile() #7561

Closed
RyanPrentiss opened this issue Aug 22, 2020 · 5 comments · Fixed by #7672
Closed

Strapi exits on fs.writeFile() #7561

RyanPrentiss opened this issue Aug 22, 2020 · 5 comments · Fixed by #7672
Labels
severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@RyanPrentiss
Copy link

Describe the bug
When writing new files to the system via fs.writeFile(), Strapi exits returning the following error:

\node_modules\strapi\lib\commands\develop.js:87
            strapiInstance.server.destroy(() => {
                                  ^

TypeError: strapiInstance.server.destroy is not a function

Steps to reproduce the behavior

  1. Create Custom Plugin strapi generate:plugin my-plugin
  2. Via {my-plugin}/config/function/bootstrap.js
fs.writeFile(`${__dirname}/../../models/testfile.txt`, "Test File Here.", (e) => e);
  1. yarn develop

Expected behavior
File should be written to system without Strapi exiting.

System

  • Node.js version: v12.16.3
  • NPM version: 6.14.7
  • Strapi version: 3.1.3
  • Database: PostgreSQL 12.3
  • Operating system: Windows 10 Home 1909
@derrickmehaffy
Copy link
Member

For this let me ping @petersg83 or @alexandrebodin as I'm not sure of the best case here, I believe in this case you are trying to edit another models lifecycles file correct?

@RyanPrentiss
Copy link
Author

For this let me ping @petersg83 or @alexandrebodin as I'm not sure of the best case here, I believe in this case you are trying to edit another models lifecycles file correct?

That is correct. I'm am attempting to dynamically create a model-js file which includes a lifecycle event for a plugin.

@RyanPrentiss
Copy link
Author

The same error occurs when executing exec('echo > test.txt'); however, exec('strapi generate:model ...') works perfectly within the bootstrap.js.

I've submitted a request for an update to allow strapi generate:model to accept an object via a --lifecycles flag.

@RyanPrentiss
Copy link
Author

I've since narrowed down the issue. Whether using echo or fs.write..., the error only seems to occur via bootstrap.js. I have not yet encountered any errors when writing files to the system following bootstrap.

@alexandrebodin
Copy link
Member

alexandrebodin commented Sep 1, 2020

the bug is coming because the server instance is not completely instantiated before the boostrap function runs. because you write files during the bootstrap, the watcher tries to reload and kill the server that is not created yet.

@alexandrebodin alexandrebodin added status: confirmed Confirmed by a Strapi Team member or multiple community members severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:strapi Source is core/strapi package and removed issue: help wanted labels Sep 1, 2020
alexandrebodin added a commit that referenced this issue Sep 1, 2020
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants