javascript - Nestjs错误导入“reflect-metadata”无法在模块外使用导入语句
问题描述
现在我有一个问题。当我添加多对多关系时,它不起作用。但之前是一对多的关系。
- 错误导入“reflect-metadata”无法在模块外使用导入语句
- 错误ReferenceError:ES模块范围内未定义导出
用户实体.ts
@Entity({ name: 'users' })
export class User implements IUser {
@PrimaryGeneratedColumn()
id: string;
@Column({ length: 25, nullable: true })
name: string;
@Column({ unique: true, length: 255 })
email: string;
@OneToMany(() => Message, (message) => message.user)
messages?: Message[];
@ManyToMany(() => Conversation, (conversations) => conversations.users)
@JoinTable({
name: 'user_conversation',
joinColumn: { name: 'user_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'conversation_id' },
})
conversations: Conversation[];
}
在文件conversation.entity.ts
@Entity({ name: 'conversations' })
export class Conversation implements IConversation {
@PrimaryGeneratedColumn()
id: string;
@Column({ name: 'title', nullable: true })
title: string;
@ManyToMany(() => User, (users) => users.conversations)
@JoinTable({
name: 'user_conversation',
joinColumn: { name: 'conversation_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'user_id' },
})
users: User[];
}
我的错误:
import "reflect-metadata";
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1001:16) ....
当我添加“类型”:“模块”到 package.json 有错误
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and ....
我尝试了很多方法,但无法解决,请帮助我。
解决方案
检查你的进口,它应该是import {...} from 'typeorm'
. 避免从'typeorm/browser'
.
推荐阅读
- apache-spark - 解决 NoClassDefFoundError: org/apache/spark/Logging 异常
- ubuntu - 如何正确配置 telegraf 以写入来自 MQTT 的 InfluxDB 数据
- c - 检查两个数字是否彼此接近
- hadoop - 将整个数据节点添加到 HDFS
- java - 从批处理文件调用蚂蚁
- sql - 带分组的 SQL 数据透视表
- git - 如何撤消“git update-ref -d refs/heads/master”?
- intellij-idea - Goland 自定义 shell 不适用于调试模式
- c# - 订阅和取消订阅单元格按钮单击事件在 iOS 11 中不起作用
- ruby-on-rails - 仅当字段属于其他表行时才存在验证字段