繁体   English   中英

Typescript导入一个React js组件,该组件由我自己编写并出现了d.ts文件。找不到模块:无法解析“ xxx”中的“ xxx”

[英]Typescript import a React js component which d.ts file writed by myself and occured Module not found: Can't resolve 'xxx' in 'xxx'

我添加了组件js的d.ts文件,如下所示:

/// <reference types="react" />

declare namespace __ReactAvatarEditor {

interface croppingRect {
    x: number,
    y: number,
    width: number,
    height: number
}

interface point {
    x: number,
    y: number
}

export interface AvatarEditorProps {
    scale?: number,
    rotate?: number,
    image?: any,
    border?: number | [number],
    borderRadius?: number,
    width?: number,
    height?: number,
    position?: point,
    color?: number[],
    style?: object,
    crossOrigin?: string,
    onDropFile?: any,
    onLoadFailure?: any,
    onLoadSuccess?: any,
    onImageReady?: any,
    onImageChange?: any,
    onMouseUp?: any,
    onMouseMove?: any,
    onPositionChange?: any,
    disableDrop?: boolean
}
export class AvatarEditor extends React.Component<AvatarEditorProps> {
}
}

declare module "react-avatar-editor"{
    export import AvatarEditorProps = __ReactAvatarEditor.AvatarEditorProps;
    export import AvatarEditor = __ReactAvatarEditor.AvatarEditor;
}
declare module "react-avatar-editor/AvatarEditor"{
    export import AvatarEditor = __ReactAvatarEditor.AvatarEditor;
    export default AvatarEditor;
}

并通过以下方式使用它:

import AvatarEditor from 'react-avatar-editor/AvatarEditor';

原始代码构造者:

在此处输入图片说明

但是当我运行项目时,它无法编译并显示错误:./src/components/DealPic.tsx找不到模块:无法在'C:\\ Users \\中解析'react-avatar-editor / AvatarEditor' xiaomin \\ Desktop \\ React \\省际肖像\\ src \\ components'

打字稿v2.5.3 React v16

我有同样的问题。 要修复它,请使用此格式的npm此软件包安装

npm install --save react-avatar-editor @types/react-avatar-editor

暂无
暂无

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

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