doublemarked / loopback-console

A command-line tool for Loopback app debugging and administration
MIT License
68 stars 6 forks source link

How to use with ES6 syntax app? #13

Closed kevzettler closed 6 years ago

kevzettler commented 6 years ago

What strategy can I take to integrate this into a ES6 app that uses import statements?

$ ./node_modules/.bin/loopback-console
/Users/kevzettler//api/app.js:3
import {generateConfig} from 'etc/environment';
^^^^^^

SyntaxError: Unexpected token import
    at new Script (vm.js:51:7)
    at createScript (vm.js:136:10)
    at Object.runInThisContext (vm.js:197:10)
doublemarked commented 6 years ago

The import is not yet supported in Node. I assume your app is running under babel, yes? You can try running the console under babel-node, something like the following: babel-node ./node_modules/.bin/loopback-console. You'll need to npm install babel-cli also.

Let me know if that works!

kevzettler commented 6 years ago

seeing the following error when launching with babel-node ./node_modules/.bin/loopback-console

 Error: Loopback app not loadable at path ._modules/loopback-console/bin/loopback-console:19] anonymous

Without the loopback-console I kick the app off like babel-node index.js

Kevs-MacBook-Pro:api kevzettler$ babel-node ./node_modules/.bin/loopback-console ./index.js
2018-04-23T17:28:09.720Z [29712] Initializing settings with environment local04-23 17:28:09.720: [etc/environment.js:26] generateConfig
2018-04-23T17:28:09.727Z [29712] Using external datasource: stage       2018-04-23 17:28:09.727: [etc/environment.js:27] generateConfig
2018-04-23T17:28:09.732Z [29712] Audit successful, continuing API boot.                   2018-04-23 17:28:09.732: [app.js:35] app.init
2018-04-23T17:28:09.761Z [29712] Initializing capabilities: CommonCapability,EventCapability,RestAPICapability,WebSocketCapability.init
2018-04-23T17:28:09.762Z [29712] Error: Loopback app not loadable at path ./index.jsloopback-console/bin/loopback-console:18] anonymous
kevzettler commented 6 years ago

What exactly should the entry point look like? my index.js looks like

// @noflow
require('./preamble');

const app = require('./app');

// Start the app.
app.start().catch((e) => {
  console.error(e.message);
  console.error(e.stack);
  process.exit(1);
});
kevzettler commented 6 years ago

@doublemarked

Looks like i'm very close. Any idea on this error? can't tell what code its coming from. The console starts to launch then crashes.

2018-04-23T17:48:56.295Z [32143] ============================================      2018-04-23 17:48:56.295: [console.js:18] initConsole
Loopback Console

Primary handles available:
 - app: The Loopback app handle
 - cb: A simplistic results callback that stores and prints
 - result: The handle on which cb() stores results

Other handles available:
  - Models: AccessToken, Affiliate, Announcement
============================================

loopback > domain.js:101
    domain.enter();
           ^

TypeError: domain.enter is not a function
    at topLevelDomainCallback (domain.js:101:12)
kevzettler commented 6 years ago

looks like a similar issue to: https://github.com/aerospike/aerospike-client-nodejs/issues/254

possibly node version related

doublemarked commented 6 years ago

I don't think this is actually related to the loopback-console, but I did some poking around - are you by chance using node v9.6.0? This error seems to be associated with a bug that was introduced around that time and then fixed in v9.6.1. Can you try swapping to either a more recent v9.x or to the LTS v8.11.1?

kevzettler commented 6 years ago

@doublemarked yes my previous messages discuss this https://github.com/doublemarked/loopback-console/issues/13#issuecomment-383665095

I can launch it with node versions < 9.6.0

My app has some asynchronous startup code that I suspect is the source of the failure.

To reiterate my previous post from: https://github.com/doublemarked/loopback-console/issues/13#issuecomment-383656747

What is the bare minimum app definition I need to get loopback-console up and running? I will need to modify my existing app code to remove the asynchronous startup code so the console can hook in.

doublemarked commented 6 years ago

The console will work with any loopback app that can be properly required as a module. So if you can go into the node cli and do require('server/server') and it returns the loopback instance, then it will work for the console. That server.js could be something as simple as module.exports = require('loopback')(), though likely you'll need some other things like boot etc.

A good way to test a realistic minimum is to scaffold a new app with the LB cli tool.

kevzettler commented 6 years ago

@doublemarked i'm encountering the following error:

/Users/kevzettler/bitmex/api/node_modules/loopback-console/repl.js:74
    if (modelHandleNames.length > 0 || ctx.customHandleNames.length > 0) {
                                                             ^
TypeError: Cannot read property 'length' of undefined
    at Object.usage (/Users/kevzettler/bitmex/api/node_modules/loopback-console/repl.js:74:62)

Any thoughts on why?

doublemarked commented 6 years ago

That is a peculiar error. Can you send me a repo that demonstrates the problem?

kevzettler commented 6 years ago

@doublemarked Unfortunately no. I cannot send a demo repo. Reason being, the app I am maintaining is using a lot of code that is proprietary and custom async startup stuff and also using on an old version of loopback, v2.

Unfortunately, have to ask high-level questions here.

doublemarked commented 6 years ago

You don't need to send me your proprietary code. What I meant is that you make a small project that reproduces the problem. Then I can assist.

On Wed, May 2, 2018, 7:54 PM Kev Zettler notifications@github.com wrote:

@doublemarked https://github.com/doublemarked Unfortunately no. I cannot send a demo repo. Reason being, the app I am maintaining is using a lot of code that is proprietary and custom async startup stuff and also using on an old version of loopback, v2.

Unfortunately, have to ask high-level questions here.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/doublemarked/loopback-console/issues/13#issuecomment-386046390, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOmVogHBBK0NSHVULhZNdSRsVZ6dKuqks5tueTFgaJpZM4TgMAP .