Getting error when creating model using lb model
====================
lb model
? Enter the model name: Poolstats
? Select the data-source to attach Poolstats to: db (memory)
(node:18144) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'type' of undefined
(node:18144) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
events.js:160
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'type' of undefined
at /Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/inquirer/lib/objects/choices.js:16:12
at Array.map (native)
at new module.exports (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/inquirer/lib/objects/choices.js:15:26)
at Prompt.module.exports (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/inquirer/lib/prompts/base.js:43:24)
at new Prompt (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/inquirer/lib/prompts/list.js:26:8)
at module.exports.PromptUI.fetchAnswer (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/inquirer/lib/ui/prompt.js:77:16)
at tryCatcher (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:63:31)
at InnerObserver.Rx.FlatMapObservable.InnerObserver.next (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:2140:43)
at InnerObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:1762:31)
at InnerObserver.tryCatcher (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:63:31)
at AutoDetachObserverPrototype.next (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:5883:51)
at AutoDetachObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:1762:31)
at InnerObserver.next (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:3547:65)
at InnerObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:1762:31)
at InnerObserver.tryCatcher (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:63:31)
at AutoDetachObserverPrototype.next (/Users/sanjay/.nvm/versions/node/v7.3.0/lib/node_modules/loopback-cli/node_modules/rx/dist/rx.js:5883:51)
node -e 'console.log(process.platform, process.arch, process.versions.node)'
darwin x64 7.3.0
npm ls --prod --depth 0 | grep loopback
├── [email protected]
├── [email protected]
├── [email protected]
@sanjay-shah Can you try it with a fresh project? Create an app, datasource then model. Then try the other way, Create an app, then model, then datasource and let me know if you run into the same error above.
@superkhau I'm having the same issue though just running the lb command. Just did a fresh install of loopback-cli.
Reproduction
Removed older version of loopback-cli with npm uninstall -g loopback-cli.
Cleared cache with npm cache clear
Installed npm install -g loopback-cli
Ran lb error that followed:
(node:11452) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: write EINVAL
(node:11452) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
events.js:160
throw er; // Unhandled 'error' event
^
Error: write EINVAL
at exports._errnoException (util.js:1022:11)
at WriteStream.Socket._writeGeneric (net.js:715:26)
at WriteStream.Socket._write (net.js:734:8)
at doWrite (_stream_writable.js:334:12)
at writeOrBuffer (_stream_writable.js:320:5)
at WriteStream.Writable.write (_stream_writable.js:247:11)
at WriteStream.Socket.write (net.js:661:40)
at MuteStream.ondata (stream.js:31:26)
at emitOne (events.js:96:13)
at MuteStream.emit (events.js:188:7)
at MuteStream.write (C:\Users\Robert\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\mute-stream\mute.js:121:8)
at Object.exports.clearLine (C:\Users\Robert\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\inquirer\lib\utils\readline.js:50:13)
at module.exports.ScreenManager.clean (C:\Users\Robert\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\inquirer\lib\utils\screen-manager.js:92:8)
at module.exports.ScreenManager.render (C:\Users\Robert\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\inquirer\lib\utils\screen-manager.js:26:8)
at Prompt.render (C:\Users\Robert\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\inquirer\lib\prompts\input.js:69:15)
at Prompt._run (C:\Users\Robert\AppData\Roaming\npm\node_modules\loopback-cli\node_modules\inquirer\lib\prompts\input.js:45:8)
Versions:
loopback-cli: 1.0.1
node: 7.1.0
Windows: 10
Extra info
Running as admin makes no difference. Produces the same error.
@RobertDiebels Thanks for the steps to reproduce. I'm going to bump this up to major for now until verified on our end.
@bajtos Reassigning to you for now as this one looks important, please verify and escalate to bug at your discretion.
@superkhau no problemo! Would like to metion that I followed the get started notes from 3.0. I'm mentioning this because I remember having to install the strongloop package separtely in the past (I'm not a frequent user of strongloop so I might be wrong about that).
Some details on what I tried to do
lb model at first (which is where I originally encountered the problem). When things didn't work I tried to start fresh in a new directory without any files/directories using lb.npm ls -g --depth=0. Which showed that I had no global strongloop packages.@RobertDiebels loopback-cli is definitely the recommended way forward (as opposed to the old slc you may remember previously. I'll try to repro on my machine using your instructions and escalate to bug soon. ;)
@RobertDiebels I do not get that error on OSX when following your steps above, so it's probably a Windows only issue. I'll see if I can repro on a VM later.
node -v // v7.5.0
npm -v // 4.1.2
@superkhau I'm trying to reproduce this now on a machine which had no previous installation. If it works there I will let you know (including versions).
@superkhau Just tested it on a Windows 10 machine with no previous installation. It works on that machine.
Versions
node -v //v6.7.0
npm -v //3.10.3
npm ls -g --depth=0 //[email protected]
I think it might be a migration thing? Maybe @sanjay-shah can confirm that?
Previous installation details
node: 7.1.0
Windows: 10
I'm not sure whether this will help as I can't go back and check the state of my pervious installation.
I was using strongloop 2.x ( I will check my package.json later today ) and had most of its modules installed on the local-level the previous cli (being slc) was installed on the global-level.
Though I'm not sure of this (as I mentioned I'm not a frequent user).
@superkhau Ok I got it working on the machine I was having issues with.
I installed a newer version of Node along with NPM. I'm now running:
npm: 4.1.2
node: 7.5.0
Running lb shows the proper sequence now. So I think it's the combination of specific versions of node and npm which caused the issue.
EDIT: I was looking for my previous installation of npm (which I didn't version check). I found my old installer and its package-date agrees with what is written on the previous releases page of nodejs
Which is:
Version LTS Date V8 npm NODE_MODULE_VERSION[1]
Node.js v7.1.0 2016-11-08 5.4.500.36 3.10.9 51
So I would install that release to see if you can reproduce it. Otherwise upgrading to the new node release fixes the issue.
@RobertDiebels Awesome, thanks for helping look into it. :bowing_man:
@sanjay-shah Can you confirm @RobertDiebels's findings and see if it works for you using a newer version of node?
@superkhau no problem 😄 ! I'll see if I can check tonight if the problem occurs again if I install the 7.1.0 version. Could be that it was some weird thing with the cache and that the update cleared everything properly.
In that case reinstalling the current version of node people are running could help (if for some reason they can't upgrade). Or it could show the same error.
Looks like the issue was fixed. I am closing this ticker, feel free to reopen it if needed.
Installing a new version of node doesn't fix the issue.
I got the same error as @sanjay-shah while trying lb model before and after updating node, npm and loopback
Before
node: 6.2.0
npm: 3.9.3
loopback: 2.0.0
After
node: 7.8.0
npm: 4.4.4
loopback: 2.1.0
Loopback module versions that I'm using:
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
@liviudobrea Can you upgrade loopback-cli to the latest version please and try again?
Also note that loopback-cli is typically installed globally via npm install -g loopback-cli. Your comment shows the CLI installed locally in our project's dependencies.
Please send us the output of lb --version to verify what version you are running.
Loopback-cli was installed globally, forgot I also had it locally. Removed local loopback, tried again, got same error.
Current loopback version is
lb -v
2.1.0 ([email protected])
Thanks, I am reopening the issue then.
I had the same issue.
One thing that leads to this is when you put your own .json files in the models directory. It just confuses the cli as it expects the .json files in that directory to be actual models.
Just move your .json files to a different location or change the extension from .json to something else and the error will go away.
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.
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.
Most helpful comment
I had the same issue.
One thing that leads to this is when you put your own
.jsonfiles in themodelsdirectory. It just confuses the cli as it expects the.jsonfiles in that directory to be actual models.Just move your
.jsonfiles to a different location or change the extension from.jsonto something else and the error will go away.