*.DEFAULT不是构造函数

发布于 2025-02-06 10:08:48 字数 1215 浏览 2 评论 0原文

我知道这个问题有很多话题,但是我读了很多,但没有找到任何答案。

我尝试通过我的nodejs项目(NEST)中的NPM使用第三方。 但是,当它编译时,我有*。默认值不是构造函数错误。

当我进入node_modules中的源时,我会看到错误。

const web3_1 = require("web3");
[...]
const getClient = async (options) => {
    const { url } = options;
    return new web3_1.default(url);
};

如果我在此处删除默认值,它像魅力一样工作,但这不是我控制的东西...

我将eSmoduleInterop true放在我的tsconfig.json中,但这是不起作用的。

这是我的tsconfig文件

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": "./",
    "incremental": true,
    "strictNullChecks": true,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "esModuleInterop": true,
    "module": "CommonJS",
    "target": "ES2018",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "skipLibCheck": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

我缺少什么?

I know there is plenty of topic around this question but I read a lot and I didn't found any answer.

I try to use a 3rd party through NPM in my nodeJS project (nest).
But when it compiles, I have the *.default is not a constructor error.

When I go into the source in the node_modules, I see the error.

const web3_1 = require("web3");
[...]
const getClient = async (options) => {
    const { url } = options;
    return new web3_1.default(url);
};

If I remove the default in here, it's working like a charm, but this is not something I control ...

I put the esModuleInterop to true in my tsconfig.json but that's not working.

Here is my tsconfig file

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": "./",
    "incremental": true,
    "strictNullChecks": true,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "esModuleInterop": true,
    "module": "CommonJS",
    "target": "ES2018",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "skipLibCheck": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟火散人牵绊 2025-02-13 10:08:48

根据他们的文档 and 他们的源代码您不应该使用<代码>默认值。正义

const web3_1 = require("web3");
[...]
const getClient = async (options) => {
    const { url } = options;
    return new web3_1(url);
};

,你应该很好。 看起来他们可能会陷入困境LL需要告诉打字条以忽略它

According to their docs and their source code you shouldn't need to use default. Just

const web3_1 = require("web3");
[...]
const getClient = async (options) => {
    const { url } = options;
    return new web3_1(url);
};

And you should be good. Looks like they may have their types messed up and you'll need to tell Typescript to ignore it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文