Reputation: 1857
I have a model called events.js where Im trying to import a helper function from a utilities file. Im not sure what Im doing wrong, perhaps im missing a loader? or this might not be possible?
the code:
import { getIdField } from 'utils/utilities';
module.exports = function(sequelize, DataTypes) {
return sequelize.define(
'events',
{
Id: getIdField(),
Name: {
type: DataTypes.STRING(150),
allowNull: false,
comment: 'null',
},
HouseId: {
type: DataTypes.INTEGER(11),
allowNull: false,
comment: 'null',
references: {
model: 'house',
key: 'Id',
},
},
Date: {
type: DataTypes.DATE,
allowNull: false,
comment: 'null',
},
Active: {
type: DataTypes.BOOLEAN,
allowNull: false,
comment: 'null',
},
},
{
tableName: 'events',
}
);
};
the error:
SyntaxError: Unexpected token {
my tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": "src",
"resolveJsonModule": true
},
"lib": ["es2015"],
"include": ["src"]
}
the exported function:
export const getIdField = (name = 'Id') => ({
// return cool stuff
});
Any ideas?
Upvotes: 1
Views: 229
Reputation: 486
This should work
const utility = require('utils/utilities');
utility.getIdField();
Upvotes: 1