facebookarchive / draft-js

A React framework for building text editors.
https://draftjs.org/
MIT License
22.56k stars 2.64k forks source link

yarn build error #2864

Open juny1zhang opened 3 years ago

juny1zhang commented 3 years ago

I got this error message when I try to execute “yarn ”。

Unhandled rejection Error in plugin "webpack-stream"
Message:
    ./lib/DraftEditorTextNode.react.js
Module not found: Error: Can't resolve './react' in '/Users/zhangjunyi/bytedance/demo/draft-js/lib'
resolve './react' in '/Users/zhangjunyi/bytedance/demo/draft-js/lib'
  using description file: /Users/zhangjunyi/bytedance/demo/draft-js/package.json (relative path: ./lib)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /Users/zhangjunyi/bytedance/demo/draft-js/package.json (relative path: ./lib/react)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/zhangjunyi/bytedance/demo/draft-js/lib/react doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        /Users/zhangjunyi/bytedance/demo/draft-js/lib/react.wasm doesn't exist
      .mjs
        Field 'browser' doesn't contain a valid alias configuration
        /Users/zhangjunyi/bytedance/demo/draft-js/lib/react.mjs doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/zhangjunyi/bytedance/demo/draft-js/lib/react.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /Users/zhangjunyi/bytedance/demo/draft-js/lib/react.json doesn't exist
      as directory
        /Users/zhangjunyi/bytedance/demo/draft-js/lib/react doesn't exist
[/Users/zhangjunyi/bytedance/demo/draft-js/lib/react]
[/Users/zhangjunyi/bytedance/demo/draft-js/lib/react.wasm]
[/Users/zhangjunyi/bytedance/demo/draft-js/lib/react.mjs]
[/Users/zhangjunyi/bytedance/demo/draft-js/lib/react.js]
[/Users/zhangjunyi/bytedance/demo/draft-js/lib/react.json]
scarcoco commented 3 years ago

me too

usecodelee commented 3 years ago

how to solve this error 😭

mariusbutuc commented 3 years ago

In an attempt to run the examples in the /examples directory, I first tried building Draft.js locally, as described in the README.

git clone git@github.com:facebook/draft-js.git
cd draft-js
yarn install

This is when I also encountered this issue:

Unhandled rejection Error in plugin "webpack-stream"
Message:
    ./lib/DefaultDraftBlockRenderMap.js
Module not found: Error: Can't resolve './react' in '/Users/marius/contrib/draft-js/lib'
resolve './react' in '/Users/marius/contrib/draft-js/lib'
  using description file: /Users/marius/contrib/draft-js/package.json (relative path: ./lib)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /Users/marius/contrib/draft-js/package.json (relative path: ./lib/react)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/marius/contrib/draft-js/lib/react doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        /Users/marius/contrib/draft-js/lib/react.wasm doesn't exist
      .mjs
        Field 'browser' doesn't contain a valid alias configuration
        /Users/marius/contrib/draft-js/lib/react.mjs doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/marius/contrib/draft-js/lib/react.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /Users/marius/contrib/draft-js/lib/react.json doesn't exist
      as directory
        /Users/marius/contrib/draft-js/lib/react doesn't exist
[/Users/marius/contrib/draft-js/lib/react]
[/Users/marius/contrib/draft-js/lib/react.wasm]
[/Users/marius/contrib/draft-js/lib/react.mjs]
[/Users/marius/contrib/draft-js/lib/react.js]
[/Users/marius/contrib/draft-js/lib/react.json]
 @ ./lib/DefaultDraftBlockRenderMap.js 18:12-30
 @ ./lib/Draft.js

After some trial and error that didn't lead (me) too far, I observed that by switching to the latest release (git checkout v0.11.7) and running yarn install at that point, everything works as expected.

What I'm sharing here is not an actual solution, but at least a workaround (switch to v0.11.7 first) and a lead: this issue was introduced in one of the 88 commits since v0.11.7 was released.


One more thing worth noticing is that the actual issue is that, in the example of DefaultDraftBlockRenderMap.js, the

const React = require('react');

in the source is translated to

var React = require("./react");

in the build output. Hope this helps. ✌🏼

florianmartens commented 3 years ago

Also seeing this error.

Eakz commented 2 years ago

October 4th. Issue still persists for build. Can't believe that they didn't fix gulp packaging issue (v0.11.7) works

betawxy commented 2 years ago

Changing https://github.com/facebook/draft-js/blob/c9878f6a4bffd3bc0d97224c19e178c7f6765a9e/scripts/module-map.js#L11 to react: 'react' worked for me.