wysiwyg-editor icon indicating copy to clipboard operation
wysiwyg-editor copied to clipboard

Does not compile with Webpack 5 (using Webpack Encore)

Open jmsche opened this issue 4 years ago • 10 comments

Expected behavior.

Webpack to successfully build Froala Editor

Actual behavior.

I'm getting this error:

Module build failed: Module not found: ./node_modules/froala-editor/js/plugins.pkgd.min.js contains a reference to the file crypto. This file can not be found, please check it for typos or update it if the file got moved.

Steps to reproduce the problem.

Using this simple configuration: https://gist.github.com/jmsche/5ce6d06b4e48c7981bdf94e1fd05b2a9

I have the issue when upgrading Webpack Encore from 0.33.0 to 1.0.0+. The main difference is that Encore uses Webpack 5 instead of Webpack <= 4.

Editor version.

Latest (3.2.6)

OS.

Linux

Browser.

N/A

More info

@Lyrkan helped me to fix it using Webpack configuration (so in my own files) but we think it should be fixed in Froala itself. Here's something that may be related: https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-nodejs-polyfills-removed

Fixed it locally using these steps:

  • adding crypto-browserify readable-stream buffer to my vendors
  • adding this to the end of webpack.config.js:
module.exports.resolve.fallback = {
    crypto: require.resolve('crypto-browserify'),
    stream: require.resolve('readable-stream')
};

jmsche avatar Jan 29 '21 09:01 jmsche

Hi,

I am using webpack encore 1.1.0 and get "TypeError: Cannot set property 'fallback' of undefined"

"resolve" is an unresolved variable in module.exports when using in webpack.config.js

module.exports.resolve.fallback = { crypto: require.resolve('crypto-browserify'), stream: require.resolve('readable-stream') };

RicoFactset avatar Feb 26 '21 11:02 RicoFactset

I solved it with:

yarn add node-polyfill-webpack-plugin

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

.addPlugin(new NodePolyfillPlugin())

RicoFactset avatar Feb 26 '21 11:02 RicoFactset

Thanks @RicoFactset , but Froala should correct this on their side. At the price they charge for this product.

lpfrenette avatar Feb 26 '21 20:02 lpfrenette

Froala should correct this on their side. At the price they charge for this product.

Like many of the issues that sit in this repo

challet avatar Apr 23 '21 16:04 challet

This is an even bigger issue with Angular 12! The webpack config is not exposed in Angular.

I found a workaround, but it's 🥴

I had to add a path to an empty file to the tsconfig (alternatively could have pointed to 'crypto-browserify', but we don't seem to need it for our case)

"compilerOptions": {
    ...
    "paths": {
      "crypto": ["./empty"]
    }
},

Also see the related angular-cli issue

mxlle avatar Jun 16 '21 10:06 mxlle

Having the same issue with webpack 5. Please fix it.

testacode avatar Jul 02 '21 21:07 testacode

Thanks for your feedback. This issue is not reproducible or have been found to be fixed on the latest Froala release v4.0.8.
Can you please upgrade and check?

AkshayCM avatar Feb 04 '22 11:02 AkshayCM

FWIW, the ember addon also had to deal with this issue.

TLDR, the existence of the crypto file causes errors when Webpack tries to include all files in the plugins folder.

The ember addon provides configuration options to list the various plugins, languages, and themes that a consumer wants to use, and the addon takes care of the actual import. This is done using a dynamic import() statement, which then causes Webpack to include all possible files in the build (including all files in the plugin folder). For whatever reason, cryptojs.min.js is not importable and causes an error. To work around this, you have to add Webpack config to exclude that file.

webpack: {
  resolve: {
    fallback: {
      crypto: false,
    },
  },
},

Panman82 avatar Feb 04 '22 14:02 Panman82

Thank you for your feedback. The request has been reported to the product management team for evaluation and consideration for an upcoming release.

AkshayCM avatar Feb 07 '22 12:02 AkshayCM

See #4390 also. Please fix this. :-)

richardkmichael avatar May 30 '22 13:05 richardkmichael