gpt4 book ai didi

javascript - 如何在 Sequelize 模型中使用导入?

转载 作者:行者123 更新时间:2023-12-03 22:19:29 24 4
gpt4 key购买 nike

我有一个名为 events.js 的模型,其中我试图从实用程序文件中导入辅助函数。
我不确定我做错了什么,也许我错过了一个装载机?或者这可能不可能?

编码:

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',
}
);
};

错误:

SyntaxError: Unexpected token {



enter image description here

我的 tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": "src",
"resolveJsonModule": true
},
"lib": ["es2015"],
"include": ["src"]
}

导出的函数:
export const getIdField = (name = 'Id') => ({
// return cool stuff
});

有任何想法吗?

最佳答案

这应该工作

const utility = require('utils/utilities'); 
utility.getIdField();

关于javascript - 如何在 Sequelize 模型中使用导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62289765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com