Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not compile with Webpack 5 (using Webpack Encore) #4156

Open
jmsche opened this issue Jan 29, 2021 · 10 comments
Open

Does not compile with Webpack 5 (using Webpack Encore) #4156

jmsche opened this issue Jan 29, 2021 · 10 comments

Comments

@jmsche
Copy link

jmsche commented Jan 29, 2021

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 jmsche changed the title Does not compile with Weback 5 (using Webpack Encore) Does not compile with Webpack 5 (using Webpack Encore) Feb 3, 2021
@RicoFactset
Copy link

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
Copy link

I solved it with:

yarn add node-polyfill-webpack-plugin

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

.addPlugin(new NodePolyfillPlugin())

@lpfrenette
Copy link

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

@challet
Copy link

challet commented Apr 23, 2021

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

@mxlle
Copy link

mxlle commented Jun 16, 2021

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

@testacode
Copy link

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

@AkshayCM
Copy link

AkshayCM commented Feb 4, 2022

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?

@Panman82
Copy link

Panman82 commented Feb 4, 2022

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,
    },
  },
},

@AkshayCM
Copy link

AkshayCM commented Feb 7, 2022

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

@richardkmichael
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants