loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Not able to create model in loopback

Open beingshashi opened this issue 10 years ago • 14 comments

? Enter the model name: account_info ? Select the data-source to attach account_info to: users (mongodb) (node:11564) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'type' of undefined

events.js:160 throw er; // Unhandled 'error' event ^

TypeError: Cannot read property 'type' of undefined at /usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/lib/objects/choices.js:16:12 at Array.map (native) at new module.exports (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/lib/objects/choices.js:15:26) at Prompt.module.exports (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/lib/prompts/base.js:43:24) at new Prompt (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/lib/prompts/list.js:26:8) at PromptUI.fetchAnswer (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/lib/ui/prompt.js:77:16) at tryCatcher (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/node_modules/rx/dist/rx.js:63:31) at InnerObserver.Rx.FlatMapObservable.InnerObserver.next (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/node_modules/rx/dist/rx.js:2140:43) at InnerObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/node_modules/rx/dist/rx.js:1762:31) at InnerObserver.tryCatcher (/usr/lib/node_modules/yeoman-generator/node_modules/yeoman-environment/node_modules/inquirer/node_modules/rx/dist/rx.js:63:31)

beingshashi avatar Nov 21 '16 12:11 beingshashi

@beingshashi It seems an old bug which is fixed in latest generator-loopback, can you confirm some module versions you are using? Thanks:

  • generator-loopback version
  • strongloop version
  • node version
  • npm version
  • your system

And please upgrade generator-loopback to latest version and see if it fix your problem.

jannyHou avatar Nov 21 '16 19:11 jannyHou

Hi @jannyHou I tried sudo npm install yeoman-generator --save and also sudo npm install generator-loopback --save , still i have same issues:- npm version =>3.10.8 node version =>v6.9.1 ubuntu 14.04

beingshashi avatar Nov 26 '16 10:11 beingshashi

@beingshashi It still works on my end:

? Enter the model name: account_info
? Select the data-source to attach account_info to: users (mongodb)
? Select model's base class PersistedModel
? Expose account_info via the REST API? (Y/n)

From the error message, it seems the datasource choice has some problem:

https://github.com/SBoudrias/Inquirer.js/blob/dcc5c6dc3786f9d04af10554a85a0333ac649e06/lib/prompts/base.js#L43

Can you fork https://github.com/strongloop/loopback-sandbox and provide me your project? I will run the command with the same project you tried, see if I can reproduce the error.

jannyHou avatar Nov 29 '16 21:11 jannyHou

@jannyHou : Its kind of big project , earlier i was not having this issues , i think i have got this after updating the node and npm , mostly. So i have recorded a video and have mailed you please check it. Still it doesn't work for you. let me know will go on skype call , i need to solve this issue any way.

beingshashi avatar Nov 30 '16 16:11 beingshashi

Hi @beingshashi for security reasons I cannot open the video you sent me, sorry for that. Some thought:

  • If you are using generator-loopback inside strongloop module, try delete it and install a global one: npm install -g generator-loopback .

  • If it's already a global one, try remove the folder and reinstall it again.

  • And please make sure thatgenerator-loopback is NOT inside your local project's folder.

    sudo npm install generator-loopback --save

    is not correct. It's supposed to work as a global module.

jannyHou avatar Dec 05 '16 22:12 jannyHou

Hi @jannyHou , I tried the above things , now i am getting this error- Error loading module "loopback": TypeError: Cannot read property 'extend' of undefined at Object. (/usr/lib/node_modules/strongloop/node_modules/generator-loopback/app/index.js:25:29) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (/usr/lib/node_modules/strongloop/lib/commands/loopback.js:9:19) at Module._compile (module.js:570:32)

beingshashi avatar Dec 20 '16 14:12 beingshashi

Hi @jannyHou ,

Kindly solve the problem asap , its been too long , and too much frustrating , not able to work with this.

beingshashi avatar Dec 20 '16 14:12 beingshashi

@beingshashi I have been trying to help but I am afraid it's not a bug of loopback. We run slc loopback:model several times everyday but never see such an error...

i think i have got this after updating the node and npm

We could not investigate more on how the reinstalled node and npm changed the behaviour.

And maybe take a look at our support plans if you need problem solved urgently: https://strongloop.com/node-js/subscription-plans/

jannyHou avatar Dec 21 '16 16:12 jannyHou

I got the same problem after adding a REST datasource in my datasource file (already containing a mongoDB one). And no more problem after just removing this REST datasource. (tried everything suggested in this issue, even changing node version, without any success).

bennekrouf avatar Jul 13 '17 07:07 bennekrouf

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 11 '17 08:09 stale[bot]

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Sep 25 '17 08:09 stale[bot]

Hi, I encountered this problem as well. And found a solution.

Well solution for me at least... 😄 I found that when creating a model, loopback searches already existing models (for example in common/models/) and their .json definitions. If he finds a file that he does not understand, throws the error. I had a config file that I used in my models in the folder and so the error occurred. Deleting the config did the trick for me 😄

Hope it helps.

JakubMifek avatar Feb 16 '18 17:02 JakubMifek

@JakubMifek your right I also had the same problem as you after removing the unwanted file lb starting behaving like it should

VisionMkhabela avatar Aug 01 '18 18:08 VisionMkhabela

hello ,i've same issue ,can you explain which files i should remove? thanks

rust4m avatar Mar 02 '19 17:03 rust4m