Unexpected errors after switching to type script

This is a template you can use to report issues. You can also drag images, videos and include Preformatted text

Expected behavior

We are upgraded to typescript recently with instructions:
https://docs.forestadmin.com/woodshop/how-tos/translate-your-app-into-typescript
dist folder is created properly, all files are compiled but we have:

  1. SyntaxError in terminal and
  2. Broken application.

Actual behavior

Failure Logs

account-features.js.map
Model creation error: SyntaxError: Unexpected token ':'
accounts.js.map
Model creation error: SyntaxError: Unexpected token ':'
agents.js.map
Model creation error: SyntaxError: Unexpected token ':'
features.js.map
Model creation error: SyntaxError: Unexpected token ':'
index.js.map
Model creation error: SyntaxError: Unexpected token ':'
interfaces
Model creation error: Error: Cannot find module '/Users/bojanantonijevic/Desktop/web-app/forest-admin/dist/models/interfaces'
Require stack:
- /Users/bojanantonijevic/Desktop/web-app/forest-admin/node_modules/sequelize/lib/sequelize.js
- /Users/bojanantonijevic/Desktop/web-app/forest-admin/node_modules/sequelize/index.js
- /Users/bojanantonijevic/Desktop/web-app/forest-admin/dist/models/index.js
- /Users/bojanantonijevic/Desktop/web-app/forest-admin/dist/middlewares/forestadmin.js
- /Users/bojanantonijevic/Desktop/web-app/forest-admin/node_modules/require-all/index.js
- /Users/bojanantonijevic/Desktop/web-app/forest-admin/dist/app.js
subscribers.js.map
Model creation error: SyntaxError: Unexpected token ':'
Example app listening on port 3000!
Your admin panel is available here: https://app.forestadmin.com/projects

Logs are triggered from models/index.js:

try {
      var model = sequelize['import'](path.join(__dirname, file));
      db[model.name] = model;
    } catch (error) {
      console.log(file);
      console.error('Model creation error: ' + error);
    }

Context

Please provide any relevant information about your setup.

  • Package Version:
  • Express Version:
  • Sequelize Version:
  • Database Dialect:
  • Database Version:
  • Project Name:

Hello @Bojan_Antonijevic,

I have been able to reproduce your exact issue.

Could you move the interfaces folder one step above and rewrite the imports in routes and models files.
It should remove the:
Cannot find module '/Users/bojanantonijevic/Desktop/web-app/forest-admin/dist/models/interfaces' error.

Also could you modify the file models/index.js:
And replace line 27:

.filter(function (file) {
    return file.indexOf('.') !== 0 && file !== 'index.js';
  })

by

.filter(function (file) {
    return file.indexOf('.') !== 0 && file !== 'index.js' && file.indexOf('.js.map') === -1;
  })

It should remove the SyntaxError: Unexpected token ':' errors.

We will update the documentation for fixing this issue too.

Tell me if it helps :smiley:

3 Likes

Thank you @Guillaume_Cisco,

Solutions from your reply fix the issues.

One more thing. Do you have any logs on your side regarding these errors from the console:

You’re welcome @Bojan_Antonijevic.
I’m glad it helped you.

Does your server correctly run on localhost with port 3310?
I can see from your previous logs it seems to run on 3000 .

Could you check your configuration, especially regarding ports.

Let me know if it helps :wink:

2 Likes

Thank you once more :slight_smile:. That solves our ERR_CONNECTION_REFUSED problems.

But we have one more.
On any collection, we get 500 with the message:

{"errors":[{"status":500,"detail":"connect ETIMEDOUT"}]}

Console errors:

Do you have a clue?

No need, solved it. Thank you very much @Guillaume_Cisco :slight_smile:

1 Like

You’re welcome :pray:

Wonderful everything is working great :tada:

2 Likes