我正在使用tinyHttp V2进行一个项目,该项目只使用EsModules。
我正在尝试用一些续集模型来制作一个示例项目,但是我什么也无法启动,类型记录编译是在抱怨模型内部的循环导入(这在commonJs中是很好的),
下面是我遇到的错误:
纱运行v1.22.17 $节点--实验-说明-分辨率=节点-实验-模块-加载程序ts-节点/esm./续集/种子/播种机(节点:10691) ExperimentalWarning:-实验-加载器是一个实验特性。此特性可能在任何时候更改(使用
node --trace-warnings ...显示创建警告的位置),在异步Loader.import (module/Loader.import/esm/module_job.js:170:25)的异步Loader.import(module/Loader.import/esm/loader.js:178:24)的异步Object.loadESM (module/process/esm_loader.js:68:5)错误命令失败之前,ReferenceError:无法访问“项目”。
这是我的TsConfig
{
"ts-node": {
"esm": true
},
"compilerOptions": {
"target": "ES2022",
"lib": ["ESNext"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
/* Modules */
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
/* JavaScript Support */
"allowJs": true,
/* Emit */
"declaration": true,
"outDir": "dist",
"downlevelIteration": true,
"preserveConstEnums": true,
"isolatedModules": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"preserveSymlinks": true,
"forceConsistentCasingInFileNames": true,
/* Type Checking */
"noImplicitAny": false,
"strictPropertyInitialization": false,
"noUnusedParameters": false,
/* Completeness */
"skipDefaultLibCheck": true,
"skipLibCheck": true
},
"include": ["*.ts", "**/*.ts"],
"exclude": ["packages/*/dist", "node_modules"]
}我试图改变模块的分辨率,但没有运气,我被卡住了,知道吗?
发布于 2022-06-01 09:35:02
我成功地完成了这个工作,解决方案是在typeOrm代码中找到的,我必须定义这种类型
export type CircularHelper<T> = T然后在模型中
@Table({
tableName: 'user',
underscored: true,
paranoid: true,
timestamps: true
})
export class User extends Model{
@Column
firstname: string
@Column
lastname: string
@Column
password: string
@Column
email: string
@HasMany(()=> UserProject)
projects: CircularHelper<UserProject>[]
@HasMany(()=> Task)
tasks: CircularHelper<Task>[]
}@Table({
tableName: 'task',
paranoid: false,
timestamps: true,
underscored: true
})
export class Task extends Model{
@Column
title: string
@Column(DataType.TEXT)
body: string
@Column
completion: number
@ForeignKey(()=> User)
@Column
userId: number
@BelongsTo(()=> User)
user: CircularHelper<User>
@ForeignKey(()=>Project)
@Column
projectId: number
@BelongsTo(()=>Project)
project: CircularHelper<Project>
}我希望它能帮到别人
https://stackoverflow.com/questions/72445405
复制相似问题