Skip to Content
New: a threat-model-first guide to choosing your network defence, plus the nym-smoldvpn dVPN package and nym-swizzle sender hygiene.

Troubleshooting bundling with Webpack

Webpack > 5 ESM

For any project using Webpack, you´ll need the following rule in your webpack.config.js above version 5:

{ test: /\.(m?js)$/, resolve: { fullySpecified: false } }

Create-react-app

General cases

To use Webpack with the code from the step-by-step examples section:

npx create-react-app nymapp --template typescript cd nymapp

Install the required dependencies, then paste the code from the step-by-step section into your app’s App.tsx.

Contract client

With webpack, the Contract client for querying or executing may need polyfills. Since create-react-app doesn’t expose the Webpack config without ejecting, override it as follows:

Install contract-clients dependencies
npm install @nymproject/contract-clients @cosmjs/cosmwasm-stargate @cosmjs/proto-signing

In your app’s App.tsx, replace the existing code with the code from the step-by-step examples section.

Polyfilling

Copy the following to your terminal and run:

npm install react-app-rewired npm install --save-dev crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process cat <<EOF > config-overrides.js const webpack = require('webpack'); const path = require('path') module.exports = function override(config) { const fallback = config.resolve.fallback || {}; Object.assign(fallback, { "crypto": require.resolve("crypto-browserify"), "stream": require.resolve("stream-browserify"), "assert": require.resolve("assert"), "http": require.resolve("stream-http"), "https": require.resolve("https-browserify"), "os": require.resolve("os-browserify"), "url": require.resolve("url") }) config.resolve.fallback = fallback; config.plugins = (config.plugins || []).concat([ new webpack.ProvidePlugin({ process: 'process/browser', Buffer: ['buffer', 'Buffer'] }) ]) config.module.rules = (config.module.rules || []).concat([ { test: /\.(m?js)$/, resolve: { fullySpecified: false } } ]) return config; } EOF

Edit the package.json file as follows:

"scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react-app-rewired test", "eject": "react-scripts eject" },
Last updated on