Loopback-next: The application can't start after deleting some model, repository, and controllers

Created on 27 Jun 2019  路  18Comments  路  Source: strongloop/loopback-next

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.
Hacktoberfest good first issue help wanted

Most helpful comment

  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.

All 18 comments

@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?

  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.

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

@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

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?

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

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

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

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?

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

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

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, 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.

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 Sure, feel free to join the Slack org (see #5048); there's a #loopback-contributors channel where we can continue an extended discussion.

May I tackle this one as my first issue ?

@MattiaPrimavera sure thing, we are looking forward to review your pull request 馃挭馃徎

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

Was this page helpful?
0 / 5 - 0 ratings