ForestAdmin / forest-express-mongoose

🌱 ExpressJS/Mongoose agent for Forest Admin to integrate directly to your existing ExpressJS/Mongoose backend application.
https://www.forestadmin.com
GNU General Public License v3.0
193 stars 28 forks source link

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

Closed GautierT closed 7 years ago

GautierT commented 7 years ago

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 commented 7 years ago

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

GautierT commented 7 years ago

I disable the code verif made by the module and it's working. And on my server Babel run before so it's okay for now

Le mer. 5 juil. 2017 17:29, Arnaud Besnier notifications@github.com a Γ©crit :

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

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ForestAdmin/forest-express-mongoose/issues/70#issuecomment-313138262, or mute the thread https://github.com/notifications/unsubscribe-auth/AFzrtRn7BT_rEA6wy3C5Km3r7OZAFwADks5sK6vGgaJpZM4OOYz1 .

arnaudbesnier commented 7 years ago

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

arnaudbesnier commented 7 years ago

@GautierT,

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

🌲🌲🌲

GautierT commented 7 years ago

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 commented 7 years ago

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

GautierT commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

GautierT commented 7 years ago

Awesome ! Thanks for this very quick fix @arnaudbesnier .