dice-roller / rpg-dice-roller

An advanced JS based dice roller that can roll various types of dice and modifiers, along with mathematical equations.
https://dice-roller.github.io/documentation
MIT License
243 stars 58 forks source link

Can't resolve 'crypto' in '/path/to/site/node_modules/@dice-roller/rpg-dice-roller/lib/esm' #251

Closed gvorbeck closed 2 years ago

gvorbeck commented 2 years ago

Using your dice roller on a Gatsby project and it's awesome!

However when I try building the static html files I get this error pointing to rpg-dice-roller and "crypo"

Generating JavaScript bundles failed

Can't resolve 'crypto' in '</path/to/my/site>/node_modules/@dice-roller/rpg-dice-roller/lib/esm'

If you're trying to use a package make sure that 'crypto' is installed. If you're trying to use a local file make sure that the path is
correct.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

I'm using the default engine and haven't selected anything called "crypto" so I'm unsure of the best way to resolve this as I don't want to break anything.

gvorbeck commented 2 years ago

installing crypto-browserify and adding

exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    resolve: {
      fallback: {
        crypto: require.resolve('crypto-browserify'),
      },
    },
  });
};

in my gatsby-node.js file, fixed this error message. Found here: https://stackoverflow.com/questions/68884421/webpack-breaking-changes-for-builtin-modules-on-gatsby-site