模块构建失败:重复声明"编辑器"

Kri*_*isT 2 reactjs semantic-ui webpack webpack-dev-server draftjs

我正在尝试在我的项目中实现Facebook提供的"RichEditor"示例以下是代码:

import React from 'react;
import { Component } from 'react';
import { Editor, EditorState, RichUtils } from 'draft-js';
import { Map } from 'immutable';

'use strict';

const { Editor, EditorState, RichUtils } = Draft;

//rest of the code...
Run Code Online (Sandbox Code Playgroud)

每当我尝试构建使用时webpack-dev-server,我都会收到以下错误.我检查了StackOverflow以查看是否有其他用户遇到了确切的错误.但是,找不到一个.

Module Build Failed: Duplicate Declaration "Editor"

'use strict';
> const { Editor, EditorState, RichUtils } = Draft;

export class ...{}
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

注意:我是ReactJS的新手.

Cod*_*er1 5

您正在Editor向上导入,然后在解构时再次定义它Draft.

您需要Editor在导入中使用别名,draft-js如下所示:

import { Editor as DEditor, EditorState, RichUtils } from 'draft-js';
Run Code Online (Sandbox Code Playgroud)

从这里你将使用Deditor而不是Editor.然后你可以自由命名Editor下面的const ...

或者,只是不要解构Draft下面的对象.

而不是使用点语法const { Editor, EditorState, RichUtils } = Draft;访问属性Draft.即Draft.Editor,Draft.EditorState等...