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

Can't use import or async or any other ES6 features in Forest config #70

Closed
GautierT opened this issue Jul 5, 2017 · 12 comments
Closed

Comments

@GautierT
Copy link

GautierT commented Jul 5, 2017

Hi, when i try to config forest like that :

'use strict';
const Liana = require('forest-express-mongoose');
const Debug  = require('debug')

const debug = Debug(('app:config:functions:forest'))

debug.log = console.log.bind(console)



Liana.collection('files', {
  fields: [{
    field: 'Signed Url',
    type: 'String',
    get: async function (object) {
      debug('object : ', object);
      return await getSignedUrlAsync(object.path)
    }
  }]
})

i have this error :

[forest] 🌳🌳🌳  Forest customization failed due to a syntax error: Unexpected token function in /Users/gautier/Documents/Projets/______/src/functions/forest/index.js:15
[forest] 🌳🌳🌳  An error occured while computing the Forest apimap. Your application apimap cannot be sent to Forest. Your Admin UI might not reflect your application models.
Error
    at /Users/gautier/Documents/Projets/_____/node_modules/forest-express/index.js:122:23

Seems that ES6 is not supported ?

@arnaudbesnier
Copy link
Member

Hi @GautierT, you're right!
This is something we have to improve, but I can't give you any ETA.

@GautierT
Copy link
Author

GautierT commented Jul 5, 2017 via email

@arnaudbesnier
Copy link
Member

@GautierT sorry for the misunderstanding on my side :(
It will be fixed this week for sure.

@arnaudbesnier
Copy link
Member

@GautierT,

The fix is now available on the latest liana version (1.4.3).

🌲🌲🌲

@GautierT
Copy link
Author

GautierT commented Oct 11, 2017

I still have the error after updating :

[forest] 🌳🌳🌳  Forest customization failed due to a syntax error: Unexpected token in /Users/gautier/Documents/Projets/____________/src/functions/forest/index.js:2
[forest] 🌳🌳🌳  An error occured while computing the Forest apimap. Your application apimap cannot be sent to Forest. Your Admin UI might not reflect your application models.
Error
    at /Users/gautier/Documents/Projets/____________/node_modules/forest-express/index.js:160:23
    at tryCatcher (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:503:31)
    at Promise._settlePromise (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:560:18)
    at Promise._settlePromiseCtx (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:597:10)
    at Async._drainQueue (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/async.js:131:12)
    at Async._drainQueues (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/async.js:136:10)
    at Immediate.Async.drainQueues (/Users/gautier/Documents/Projets/____________/node_modules/forest-express/node_modules/bluebird/js/release/async.js:16:14)
    at runCallback (timers.js:637:20)
    at tryOnImmediate (timers.js:610:5)
    at processImmediate [as _immediateCallback] (timers.js:582:5)

First 2 line of src/forest/index.js

'use strict'
import Liana from 'forest-express-mongoose'

@arnaudbesnier
Copy link
Member

What happens if you set a semi-colon at the end of the import line?

@GautierT
Copy link
Author

I still have the same error.

I had to remove this block

return codeSyntaxInspector
  .extractCodeSyntaxErrorInDirectoryFile(directorySmartImplementation)
  .then(function (hasError) {
    if (hasError) {
    throw new Error();
    } else {
      // NOTICE: Do not display an error log if the forest/ directory
      //         does not exist.
      return requireAllModels(Implementation,
        directorySmartImplementation, false);
    }
  });

On forest-express/index.js line 160 and replace it by

return requireAllModels(Implementation,
        directorySmartImplementation, false);

@arnaudbesnier
Copy link
Member

@GautierT sure it will work if you remove this part of the code, but we want to keep that part to prevent unexpected errors while generating the UI based on your Forest customization.

Can you help us by digging into your Forest customization code in order to find what is not accepted by the syntax inspector?

@GautierT
Copy link
Author

GautierT commented Oct 11, 2017

I only have this problem in my dev environment.
On production the code is compiled by babel.
I start my dev server like this : DEBUG=app:* DEBUG_DEPTH=15 nodemon ./node_modules/.bin/babel-node src/index.js

Here is the first lines of src/forest/index.js

'use strict'
import Liana from 'forest-express-mongoose';
import Events from './../../models/events'
import last from 'lodash/last'
import get from 'lodash/get'
import { getSignedUrlAsync } from '../files'

const Debug = require('debug')

const debug = Debug(('app:config:functions:forest'))

debug.log = console.log.bind(console)

Liana.collection('files', {
  fields: [{
    field: 'Signed Url',
    type: 'String',
    get: async function (object) {
      return await getSignedUrlAsync(object.path)
    }
  }]
})

What do you need ?

@arnaudbesnier
Copy link
Member

Just to check what is the origin of the issue.
But I found it by my-self. If you comment out your imports your server should start without error. So the import syntax does not seem to be accepted by the syntax validator.
I'll search why.

@arnaudbesnier
Copy link
Member

@GautierT you can upgrade to the latest liana version (forest-express-mongoose@1.4.9), it should be fixed now.

@GautierT
Copy link
Author

Awesome ! Thanks for this very quick fix @arnaudbesnier .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants