首页 > 解决方案 > 在 TypeScript 中使用 EditorJS 时遇到问题

问题描述

我正在尝试使用 TypeScript 并尝试将 EditorJS 与 Typescript 一起使用。到目前为止,我为我的项目下载并安装了 EditorJS,npm i @editorjs/editorjs一切顺利。

然后,我尝试使用以下行在我的项目中使用 EditorJS:

import EditorJS from '@editorjs/editorjs';

但是,构建失败并显示以下消息:

Cannot find type definition file for 'data-formats'

Cannot find module '@editorjs/editorjs'

该文件夹module_modules/@editorjs确实存在于我的项目中,所以我无法弄清楚这里可能存在什么问题。

我希望有人能指出我正确的方向

以下是我的项目结构的概述:

-/node_modules/
    -- /@editorjs
    -- /editorjs
-/src/
    -- /@types/
    -- Main.ts
- package.json

我省略了与 editorjs 无关的所有其他文件夹

我的 tsconfig.json 如下:

{
  "compilerOptions": {
    "module": "es6",
    "target": "ES2017",
    "removeComments": true,
    "preserveConstEnums": true,
    "outDir": "./build",
    "sourceRoot": "./src/",
    "rootDir": "./src/",
    "sourceMap": true,
    "baseUrl": "./",    
    "typeRoots": [
        "./node_modules/@types",
        "./src/@types/",
        "./node_modules/@editorjs/editorjs/types"       
    ]       
  }
}

在 packakge.json 我添加了以下依赖项:

"@editorjs/editorjs": "^2.17.0",

提前致谢。

标签: javascripttypescriptnpmeditorjs

解决方案


在导入语句 EditorJS 中的类型应该是 CamelCase。

改变

import EditorJS from '@editorjs/editorjs';

import **EditorJs from '@editorjs/editorjs';

推荐阅读