【问题标题】:Uncaught TypeError: ... is not a constructor - Typescript module import errorUncaught TypeError: ... is not a constructor - Typescript 模块导入错误
【发布时间】:2021-12-23 02:08:13
【问题描述】:

我有一个从 github 克隆并使用 npm install 安装的示例 typscript 项目。

在 index.ts 中,我正在尝试导入第三方模块 (https://github.com/ScatterCo/Depthkit.js)。该模块已使用npm install depthkit下载到node_modules文件夹中

要导入我尝试过的模块 import {DepthKit} from 'depthkit/build/depthkit';import * as DK from 'depthkit/build/depthkit';

但是当我运行 var depthkit = new DepthKit();var depthkit = new DK.DepthKit(); 我收到一个错误Uncaught TypeError: depthkit_1.DepthKit is not a constructor

我该如何解决这个问题?

【问题讨论】:

    标签: typescript import module


    【解决方案1】:

    根据我阅读的代码,正确的导入应该是import DepthKit from "depthkit",因为 DepthKit 类是索引默认导出

    【讨论】:

    • 谢谢,但是node_modules中depthkit文件夹的根目录下不存在depthkit.js文件,它实际上在depthkit/build/depthkit.js 你是说我不需要专门指导进口商到这个js文件路径?
    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 2021-07-13
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多