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
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
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.
Windows 10 'win32', 'x64', '10.16.0'
[ ] 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",
Greetings :wave: to all Hacktoberfest 2020 participants!
Here are few tips 馃憖 to make your start easier, see also #6456:
#loopback-contributors channel, you can join our Slack workspace here. @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?
Once you remove certain TS files, please run npm run clean && npm run build to remove staled JS files.
You're responsible for updating index.ts at the moment as our CLI does not support delete.
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 buildwhich are (if) necessary for loopback to generatedistshould run automatically beforenpm startto 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
Most helpful comment
Once you remove certain TS files, please run
npm run clean && npm run buildto remove staled JS files.You're responsible for updating
index.tsat the moment as our CLI does not supportdelete.Our CLI commands only provide
createabilities, notupdateordelete.