Bắt đầu dự án mới với lệnh 'lồng mới'. Hoạt động tốt cho đến khi tôi thêm tập tin thực thể vào nó.
Có lỗi sau:
nhập {Thực thể, Cột, ChínhGeneratedColumn} từ 'typeorm';
^ ^ ^ ^ ^ ^ ^
Cú pháp: Không thể sử dụng câu lệnh nhập bên ngoài mô-đun
Tôi nhớ cái gì
Thêm thực thể vào mô-đun:
import { Module } from '@nestjs/common';
import { BooksController } from './books.controller';
import { BooksService } from './books.service';
import { BookEntity } from './book.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [TypeOrmModule.forFeature([BookEntity])],
controllers: [BooksController],
providers: [BooksService],
})
export class BooksModule {}
app.module.ts:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Connection } from 'typeorm';
import { BooksModule } from './books/books.module';
@Module({
imports: [TypeOrmModule.forRoot()],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
srcthư mục của bạn ? Nếu bạn đang sử dụng TypeORM, bạn có thể hiển thị của bạn TypeOrmModulenhập khẩu trong AppModulecủa importsmảng? Có thể có điều gì đó không đúng với cấu hình mà chúng ta không thể thấy