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

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

Closed
1 task
m98 opened this issue Jun 27, 2019 · 18 comments · Fixed by #6588
Closed
1 task

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

m98 opened this issue Jun 27, 2019 · 18 comments · Fixed by #6588
Assignees
Labels
good first issue Hacktoberfest Tasks ready for new contributors to work on help wanted

Comments

@m98
Copy link

m98 commented Jun 27, 2019

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 👋 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 m98 added the bug label Jun 27, 2019
@dhmlau
Copy link
Member

dhmlau commented Jun 27, 2019

@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 dhmlau self-assigned this Jun 27, 2019
@raymondfeng
Copy link
Contributor

  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.

@bajtos
Copy link
Member

bajtos commented Jun 28, 2019

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

@m98
Copy link
Author

m98 commented Jun 28, 2019

@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

@dougal83
Copy link
Contributor

dougal83 commented Jun 30, 2019

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?

@godartm
Copy link

godartm commented Jul 25, 2019

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

@hacksparrow
Copy link
Contributor

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

@dhmlau dhmlau assigned godartm and unassigned dhmlau Jul 25, 2019
@dhmlau
Copy link
Member

dhmlau commented Jul 25, 2019

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

@garethhcoleman
Copy link

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?

@raymondfeng
Copy link
Contributor

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

@garethhcoleman
Copy link

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

@garethhcoleman
Copy link

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.

@dhmlau
Copy link
Member

dhmlau commented Apr 21, 2020

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

@garethhcoleman
Copy link

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?

@achrinza
Copy link
Member

achrinza commented Apr 21, 2020

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

@bajtos bajtos added Hacktoberfest Tasks ready for new contributors to work on and removed Docs labels Sep 29, 2020
@MattiaPrimavera
Copy link
Contributor

May I tackle this one as my first issue ?

@bajtos
Copy link
Member

bajtos commented Oct 12, 2020

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

MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 17, 2020
fix build error when manually deleting a model, repository or controller

fix loopbackio#3259
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 17, 2020
fix build error when manually deleting a model, repository or controller

fix loopbackio#3259
@mdbetancourt
Copy link
Contributor

mdbetancourt commented Oct 17, 2020

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

MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 18, 2020
fix build error when manually deleting a model, repository or controller

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 18, 2020
add rebuild script to more concisely express "clean && build" procedure & remove code duplication

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 19, 2020
add rebuild script to more concisely express "clean && build" procedure & remove code duplication

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 19, 2020
Add rebuild npm script in example projects & call it within pretest & prestart scripts

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 20, 2020
Keep hooks pre/post implicit calls. This will work with yarn 1.x only

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 21, 2020
…or controller

- force a clean build in prestart npm script
- add rebuild script to more concisely express "clean && build" procedure & remove code duplication

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
MattiaPrimavera added a commit to MattiaPrimavera/loopback-next that referenced this issue Oct 21, 2020
Add rebuild npm script in example projects & call it within pretest & prestart scripts

fix loopbackio#3259

Signed-off-by: Mattia Primavera <[email protected]>
raymondfeng pushed a commit that referenced this issue Oct 21, 2020
…or controller

- force a clean build in prestart npm script
- add rebuild script to more concisely express "clean && build" procedure & remove code duplication

fix #3259

Signed-off-by: Mattia Primavera <[email protected]>
raymondfeng pushed a commit that referenced this issue Oct 21, 2020
Add rebuild npm script in example projects & call it within pretest & prestart scripts

fix #3259

Signed-off-by: Mattia Primavera <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Hacktoberfest Tasks ready for new contributors to work on help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.