An error occured while computing the Forest schema

I am trying to deploy in production my app. It works fine on local environment but not in production

Expected behavior

I’ve created a smart field representing a pre signed url from AWS S3. Here’s the configuration :

collection(‘users’, {
actions: ,
fields: [{
field: “DOC ID”,
type: ‘String’,
get: async user => {
if (user?.identityDocuments[0]?.name) {
return await generatePreSignedUrlS3ForGet(user.identityDocuments[0].name, 300) //function used to generate a presigned URL from S3
} else {
return ‘-’
}
}
}],
segments: ,
});

This code works fine on local environment

Actual behavior

I’ve deployed the app on an Heroku instance. I have a log saying : “An error occured while computing the Forest schema. Your application schema cannot be synchronized with Forest. Your admin panel might not reflect your application models definition. Unexpected token ‘.’”

The ‘.’ points towards ‘user?.’ and I don’t understand why it is an unexpected token.

Context

  • forest-express-mongoose: 6.7.2
  • express: ~4.17.1
  • mongoose: ~5.8.2

Hello @barthelemy !

Welcome to the Forest Admin Community!

Is it possible for you to send us more information regarding the stack trace?
Are you sure, the unexpected token comes from user?.

Is that so, is there any difference between the code in development and the one in production?

I see you are using the optional chaining operator from babel.
Is your babel configuration correctly set up in production?

Let me know :slight_smile:

PS: you can use triple backquotes for posting code, it will increase the readibility :smiley:

Hello Guillaume, thanks for your prompt answer!
What would you need in the stack trace ? I don’t think it really comes from the user?. but that’s the message I get from the Heroku instance :

I don’t use babel on my local environment

Sorry if it looks odd, I’m quite unfamiliar with this!

OK @barthelemy, no issue :slight_smile:

It looks like a babel configuration issue to me, but let’s be sure of that.

What if you modify your code from:

if (user?.identityDocuments[0]?.name) {

to

if (user && user.identityDocuments && user.identityDocuments[0] && user.identityDocuments[0].name) {

Do you have the same kind of error?

Thank you it worked, you’ve made my day! Just for my understanding, I don’t see any babel dependencies installed on my local environement, do you know where it could be from?

I’m glad it helped you.

I think there is something different between your local and production environment.
But that would require introspection with the architecture code under my eyes.

Definitively it looks like a configuration issue, try to look how is deployed your project :slight_smile:

hello @barthelemy!

The optional chaining support was introduced in node v14 so in order to use it without any additional babel configuration you need to have at least this version.

Most probably you have different node versions installed on local (at least v14) and remote (probably v12) environments.

I am not sure about Heroku’s default behavior if the engine version is not specified, but you should be able to check both versions by doing node -v

If indeed Heroku is using v12 as the default one, you can try to enforce the v14 by adding

"engines": {
     "node": "14.15.4"
  },

in the package.json file of your project.

Let me know if this helps or if you have any more questions :slightly_smiling_face:

Hello @olesyak, thanks for your answer, you’re right about the node version :slight_smile:

2 Likes