HubSpot / draft-convert

Extensibly serialize & deserialize Draft.js ContentState with HTML.
Apache License 2.0
483 stars 94 forks source link

"Error: 'convertToRaw' is not exported by node_modules/draft-js/lib/Draft.js" in version 2.1.8 #153

Open serafinomb opened 5 years ago

serafinomb commented 5 years ago

Hello, during a clean npm install I encountered the error reported below.

These are the "draft-js" and "draft-convert" versions in my "package.json" file.

"dependencies": {
    "draft-convert": "^2.0.1",
    "draft-js": "^0.10.5",
    ...
}

And the error encountered:

    [!] Error: 'convertToRaw' is not exported by node_modules/draft-js/lib/Draft.js
    https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
    node_modules/draft-convert/esm/convertToHTML.js (5:9)
    3: import React from 'react';
    4: import ReactDOMServer from 'react-dom/server';
    5: import { convertToRaw } from 'draft-js';
                ^
    6: import encodeBlock from './encodeBlock';
    7: import blockEntities from './blockEntities';

I updated the "draft-convert" version to "2.1.7" momentarily to fix the issue. It seems that the latest release has incompatibilities with the latest release (as of today) of "draft-js".

Please let me know if I do anything to help debug the issue, thank you.

dumistoklus commented 5 years ago

@serafinomb, To fix this error add convertToRaw to commonjs rollup plugin section in rollup config.

plugins: [
  commonjs({
    namedExports: {
      'node_modules/draft-js/lib/Draft.js': [
        'convertToRaw',
        // ...other exports
      ]
    }
  })
]
TrySound commented 5 years ago

Similar way with kinda automating named exports list

import * as draftJs from 'draft-js';
commonjs({
  namedExports: {
    'draft-js': Object.keys(draftJs)
  }
})