loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

The application can't start after deleting some model, repository, and controllers

Open m98 opened this issue 7 years ago • 18 comments

Steps to reproduce

Generate two model, repository and controllers and build, then delete one of the model, repository, and controllers, and try to build again. In my case, I got an error from the model and repository which I already deleted, and it was trying to access it before the build process was complete

Current Behavior

The application on npm start tries to access deleted model or repository after I delete model and repository file, and also its link from index.ts

Expected Behavior

An easy way to delete a model, repository, and controllers using CLI to reduce such errors, And also not getting an error on manually deleting files.

Additionally, I tried to delete dist directory to rebuild the project, and I was getting an error that it was not able to build the project again without having access to dist directory which sounds odd if you compare it with other frameworks which dist is in .gitignore because it's only useful for build purposes.

Additional information

Windows 10 'win32', 'x64', '10.16.0'

Acceptance criteria

  • [ ] Modify the project template files package.json.ejs and package.plain.json.ejs to run npm run clean as part of the prestart script.

    - "prestart": "npm run build",
    + "prestart": "npm run clean && npm run build",
    

🎆 Hacktoberfest 2020

Greetings :wave: to all Hacktoberfest 2020 participants!

Here are few tips 👀 to make your start easier, see also #6456:

  • Before you start working on this issue, please leave a comment to let others know.
  • This issue consists of several tasks to work on, it may feel like a too big effort to undertake. Don't worry! It's perfectly fine to pick just one item from the list and leave the rest for somebody else. In fact, we prefer to have a dedicated pull request for each part, to make it easier for us to review the changes and get the pull request landed faster. Baby steps FTW! Remember, every little helps.
  • If you are new to GitHub pull requests, then you can learn about the process in Submitting a pull request to LoopBack 4.
  • If this is your first contribution to LoopBack, then please take a look at our Developer guide.
  • Feel free to ask for help in #loopback-contributors channel, you can join our Slack workspace here.

m98 avatar Jun 27 '19 11:06 m98

@m98, what's the error you're getting when running npm start?
I suspect that when you're deleting the models or other artifacts, the index.ts of the corresponding folders are not updated. Could you please check if that's the case?

dhmlau avatar Jun 27 '19 12:06 dhmlau

  1. Once you remove certain TS files, please run npm run clean && npm run build to remove staled JS files.

  2. You're responsible for updating index.ts at the moment as our CLI does not support delete.

  3. Our CLI commands only provide create abilities, not update or delete.

raymondfeng avatar Jun 27 '19 14:06 raymondfeng

It would be nice to capture the information from Raymond's comment in our documentation. Any volunteers to contribute such changes?

bajtos avatar Jun 28 '19 11:06 bajtos

@bajtos Why the CLI should not do all of these itself?

As Angular CLI which handles many different cases itself, and I believe things like npm run clean && npm run build which are (if) necessary for loopback to generate dist should run automatically before npm start to reduce such errors

m98 avatar Jun 28 '19 18:06 m98

I believe things like npm run clean && npm run build which are (if) necessary for loopback to generate dist should run automatically before npm start to reduce such errors

@m98 Fortunately you can alter the following script in package.json to just that: "prestart": "npm run build", to "prestart": "npm run clean && npm run build",

I don't think clean is always necessary so it's omitted but can easily be added as above. If there is a say a remove model command, obviously it follows a clean would be required maybe?

dougal83 avatar Jun 30 '19 16:06 dougal83

Hi , can i take this issue and update the documentation ?

godartm avatar Jul 25 '19 13:07 godartm

@godartm yes, please open a PR. Your contribution will be much appreciated.

hacksparrow avatar Jul 25 '19 13:07 hacksparrow

Thanks @godartm. I've assigned this issue to you. :)

dhmlau avatar Jul 25 '19 14:07 dhmlau

I just ran up against this issue, thanks to @raymondfeng for succinctly providing the solution. I like also the suggestion of @dougal83 to add the clean to the build script. I will do that now as I cannot see any downsides, unless there are negatives I'm missing?

garethhcoleman avatar Apr 20 '20 16:04 garethhcoleman

I'm ok to run npm run clean as part of prestart.

raymondfeng avatar Apr 20 '20 17:04 raymondfeng

Would it be useful for me to attempt to compose a PR to that effect @raymondfeng?

garethhcoleman avatar Apr 20 '20 17:04 garethhcoleman

OK - I looked through several dozen places and I can't find where the one for the app is generated and therefore where to lodge PR against... sorry.

garethhcoleman avatar Apr 20 '20 18:04 garethhcoleman

@garethhcoleman, the package.json template can be found in https://github.com/strongloop/loopback-next/blob/master/packages/cli/generators/project/templates/package.json.ejs, if this is what you're looking for.

dhmlau avatar Apr 21 '20 02:04 dhmlau

That's so strange! Thank you @dhmlau - I looked at that file as it seemed like the obvious candidate but then I noticed that it already had the "pretest": "npm run clean && npm run build" defined! So I reasoned that I must have got lost trying to follow the logic of the generators.... sorry for clogging up the issue perhaps better taking this discussion to gitter or slack/irc/etc?

garethhcoleman avatar Apr 21 '20 08:04 garethhcoleman

@garethhcoleman Sure, feel free to join the Slack org (see #5048); there's a #loopback-contributors channel where we can continue an extended discussion.

achrinza avatar Apr 21 '20 09:04 achrinza

May I tackle this one as my first issue ?

MattiaPrimavera avatar Oct 11 '20 16:10 MattiaPrimavera

@MattiaPrimavera sure thing, we are looking forward to review your pull request 💪🏻

bajtos avatar Oct 12 '20 14:10 bajtos

here a recommendation instead of use pre, post hook is better to use a nomal and call it explicitly for yarn 2 users https://yarnpkg.com/getting-started/migration#explicitly-call-the-pre-and-post-scripts

mdbetancourt avatar Oct 17 '20 17:10 mdbetancourt