JavaScript SDK Troubleshooting
Table of Contents#
Vite Build Errors#
Q: I'm getting warnings like "Module "buffer" has been externalized for browser compatibility" when building with Vite. How do I fix this?#
A: This issue is caused by missing Node polyfills in your bundled web application. To resolve it:
-
Install
vite-plugin-node-polyfills
:_10npm i --save-dev vite-plugin-node-polyfills_10# or_10yarn add --dev vite-plugin-node-polyfills -
Update your
vite.config.js
orvite.config.ts
:_10import { defineConfig } from 'vite'_10import react from '@vitejs/plugin-react'_10import { nodePolyfills } from 'vite-plugin-node-polyfills'_10_10export default defineConfig({_10plugins: [_10react(),_10nodePolyfills()_10],_10}) -
Restart your development server.
Q: I'm getting a "Cannot read properties of undefined (reading 'from')" error in hdkey-without-crypto.js. How do I fix this?#
A: This error is related to the ethereum-cryptography
package. To fix it:
-
Install the
buffer
package:_10npm install buffer_10# or_10yarn add buffer -
Update your
vite.config.ts
:_17import { defineConfig } from 'vite'_17import react from '@vitejs/plugin-react'_17import { nodePolyfills } from 'vite-plugin-node-polyfills'_17_17export default defineConfig({_17plugins: [_17react(),_17nodePolyfills({_17globals: {_17Buffer: false_17}_17})_17],_17define: {_17global: {},_17},_17}) -
Restart your Vite dev server.
Q: I'm getting a "require is not defined" error when using vite preview
. How do I fix this?#
A: Add the following to your vite.config.ts
file:
_10export default defineConfig({_10 // ... your existing config_10 build: {_10 commonjsOptions: {_10 transformMixedEsModules: true_10 }_10 },_10})
Then rebuild your project before running vite preview
.
Webpack Build Errors#
Q: I'm getting "Module not found" errors for Node.js core modules when using create-react-app. How do I fix this?#
A: This is due to Webpack 5 not including Node.js polyfills by default. To fix it:
-
Install required packages:
_10npm install --save-dev react-app-rewired crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process_10# or_10yarn add --dev react-app-rewired crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process -
Create a
config-overrides.js
file in your project root:_27const webpack = require('webpack');_27module.exports = function override(config) {_27const fallback = config.resolve.fallback || {};_27Object.assign(fallback, {_27crypto: require.resolve('crypto-browserify'),_27stream: require.resolve('stream-browserify'),_27assert: require.resolve('assert'),_27http: require.resolve('stream-http'),_27https: require.resolve('https-browserify'),_27os: require.resolve('os-browserify'),_27url: require.resolve('url'),_27});_27config.resolve.fallback = fallback;_27config.plugins = (config.plugins || []).concat([_27new webpack.ProvidePlugin({_27process: 'process/browser',_27Buffer: ['buffer', 'Buffer'],_27}),_27]);_27config.module.rules.push({_27test: /\.m?js/,_27resolve: {_27fullySpecified: false,_27},_27});_27return config;_27}; -
Update your
package.json
scripts:_10"scripts": {_10"start": "react-app-rewired start",_10"build": "react-app-rewired build",_10"test": "react-app-rewired test",_10"eject": "react-scripts eject"_10}
Q: How do I deal with 'failed to parse source map' warnings?#
A: You can disable these warnings by adding GENERATE_SOURCEMAP=false
to your start script in package.json
:
_10"scripts": {_10 "start": "GENERATE_SOURCEMAP=false react-app-rewired start",_10 // ..._10},
Next.js Build Errors#
Q: I'm getting a "Named export 'curves' not found" error with the elliptic package in Next.js 13/14. How do I fix this?#
A: Add the following to your next.config.js
:
_10const nextConfig = {_10 // ... other next config_10 experimental: {_10 esmExternals: false,_10 },_10};
Q: I'm having issues importing SDK modules in Next.js 13 with the App Router. What should I do?#
A: Use the SDK Code Splitting method for imports:
_10import Openfort from '@openfort/openfort-js';
Q: I'm getting a "Cannot read properties of undefined (reading 'fromMasterSeed')" error in Next.js 12. How do I fix this?#
A: Add the following to your next.config.js
:
_10const nextConfig = {_10 // ... other next config_10 experimental: {_10 esmExternals: false,_10 },_10};
Q: I'm getting a "Could not detect network" error on Next.js 14 API endpoint with JsonRpcProvider. How do I fix this?#
A: You have three options:
- Downgrade to Next.js 13
- Upgrade to Ethers v6
- Use the solution provided in this GitHub issue discussion