简体   繁体   English

TypeError: bn_js_1.default 不是构造函数

[英]TypeError: bn_js_1.default is not a constructor

Hello everone, i just implement bn.js in class validator DTO.大家好,我只是在 class 验证器 DTO 中实现bn.js。 And got some error like this:并得到一些像这样的错误:

TypeError: bn_js_1.default is not a constructor at Object.transformFn TypeError: bn_js_1.default 不是 Object.transformFn 的构造函数

anyone can help me?任何人都可以帮助我吗? here's the DTO:这是 DTO:

import BN from 'bn.js';
import { Transform } from 'class-transformer';

export class IWCreateNftCollectionV1ReqDTO {
  @Transform(({ value }) => new BN(value.toString()))
  royalties:BN;
}

And the package.json和 package.json

"dependencies": {
    "@types/bn.js": "^5.1.0",
    "bn.js": "^5.2.0"
}

Thanks谢谢

UPDATE Solved by adding bellow in tsconfig.json更新通过在tsconfig.json中添加波纹管解决

{
  "compilerOptions": {
    ...
    "esModuleInterop": true,
  },
}

Seem like bn.js doesn't use default exports.似乎 bn.js 不使用默认导出。 You can either set esModuleInterop: true in your tsconfig , or you should be able to do import * as BN from 'bn.js';您可以在 tsconfig 中设置tsconfig esModuleInterop: true ,或者您应该能够import * as BN from 'bn.js'; if you don't want to modify that setting如果您不想修改该设置

Add the setting esModuleInterop: true in the tsconfig file worked for me.在对我有用的 tsconfig 文件中添加设置esModuleInterop: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM