下面是我启动nest服务器时遇到的问题:
back-end/node_modules/@nestjs/common/decorators/core/optional.decorator.js:22
const args = Reflect.getMetadata(constants_1.OPTIONAL_DEPS_METADATA, target) || [];
^
TypeError: Reflect.getMetadata is not a function
at /Users/lucabento-versace/OneDrive-Ynov/Projets/3eme_annee/WEB/TrueEat/back-end/node_modules/@nestjs/common/decorators/core/optional.decorator.js:22:34
at /Users/lucabento-versace/OneDrive-Ynov/Projets/3eme_annee/WEB/TrueEat/back-end/node_modules/@nestjs/common/node_modules/tslib/tslib.js:104:41
at Object.__decorate (/Users/lucabento-versace/OneDrive-Ynov/Projets/3eme_annee/WEB/TrueEat/back-
end/node_modules/@nestjs/common/node_modules/tslib/tslib.js:99:99)
at Object.<anonymous> (/Users/lucabento-versace/OneDrive-Ynov/Projets/3eme_annee/WEB/TrueEat/back-end/node_modules/@nestjs/common/services/console-logger.service.js:204:43)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
我徒劳地测试了一下:npm i reflect-metadata
我已经查看了关于同一错误的问题,但找不到任何解决方案
3条答案
按热度按时间3htmauhk1#
正如user @hhearts在上面的评论中提到的,通常通过将“reflect-metadata”导入到全局名称空间中来解决这个问题(这样您只需执行一次。
但您可以根据需要在范围内执行此操作。
例如,对于(p)react,您可以在
App.ts
中的第一次导入时执行此操作hpxqektj2#
从
@nestjs/common/pipes
导入ValidationPipe
,而不是从@nestjs/common/pipes/validation.pipe
导入ny6fqffe3#
对于我来说,我把
import { ValidationPipe } from '@nestjs/common/pipes'
改成了import { ValidationPipe } from '@nestjs/common'
,现在它可以工作了