Troubleshooting
This document provides solutions for common issues encountered when using Telescope and Telescope-generated code.
Common Issues
Webpack Configuration in Create React App
When using Telescope-generated code with Create React App (CRA), you might encounter issues with polyfills and certain modules not being properly resolved due to CRA's webpack configuration restrictions.
Solution
You need to customize the webpack configuration. Since CRA doesn't allow direct webpack configuration modifications, you can use react-app-rewired
to override the default configuration:
- Install required packages:
npm install --save-dev react-app-rewired customize-cra
- Create a
config-overrides.js
file in the root of your project:
const { override, addWebpackAlias, addWebpackPlugin } = require('customize-cra');
const webpack = require('webpack');
module.exports = override(
// Add polyfills and resolve issues
addWebpackPlugin(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
})
),
addWebpackAlias({
'stream': 'stream-browserify',
'path': 'path-browserify',
'crypto': 'crypto-browserify',
'http': 'stream-http',
'https': 'https-browserify',
'os': 'os-browserify/browser',
})
);
- Modify your
package.json
scripts to usereact-app-rewired
:
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
}
- Install the necessary polyfill packages:
npm install --save-dev buffer process stream-browserify path-browserify crypto-browserify stream-http https-browserify os-browserify
Babel Configuration
If you're using a custom Babel setup, you might encounter syntax errors with features like numeric separators or optional chaining that are used in Telescope-generated code.
Solution
Make sure your Babel configuration includes the necessary plugins:
npm install --save-dev @babel/plugin-proposal-numeric-separator @babel/plugin-proposal-optional-chaining @babel/plugin-proposal-nullish-coalescing-operator
Add these plugins to your .babelrc
or babel.config.js
:
{
"plugins": [
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator"
]
}
Or if you're using a preset:
{
"presets": [
["@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions", "not dead"]
}
}]
]
}
Long Type Errors
When using Telescope-generated code, you might see extremely long and complex TypeScript errors that are difficult to understand.
Solution
- Use a specific TypeScript version that works well with CosmJS (4.7.x or later recommended)
- Simplify your types with type assertions in places where TypeScript is having trouble
- Add
//@ts-ignore
comments for problematic lines as a last resort - Enable the
useDeepPartial
option in your Telescope configuration to simplify partial types
Module Resolution Issues
You might encounter "Cannot find module" errors when importing from Telescope-generated code.
Solution
Check your tsconfig.json
to ensure it has the correct module resolution settings:
{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"baseUrl": "."
}
}
Browser Compatibility Issues
Telescope-generated code uses modern JavaScript features that might not be compatible with older browsers.
Solution
- Ensure you have proper polyfills added to your project
- Configure Babel to target the browsers you need to support
- Consider using a tool like
core-js
for comprehensive polyfills:
npm install core-js
Then import it at the top of your entry file:
import 'core-js/stable';
WebAssembly Support
Some CosmJS dependencies use WebAssembly, which might cause issues in certain environments.
Solution
Make sure your bundler is configured to handle WebAssembly files (.wasm). For webpack:
module.exports = {
// ...
experiments: {
asyncWebAssembly: true,
},
};
Specific Blockchain Issues
Transaction Broadcasting Fails
If transactions are being rejected by the network:
- Ensure account sequence is correct
- Verify gas settings are appropriate
- Check that the chain ID matches the network you're connecting to
- Verify that the RPC endpoint is functioning correctly
Query Errors
If queries are failing:
- Check the RPC or API endpoint URL
- Ensure the blockchain node is synchronized
- Verify query parameters are correctly formatted
- Check for rate limiting issues
Debugging Tips
Enable Console Logging
Add more verbose logging to help identify issues:
const client = await SigningStargateClient.connectWithSigner(
rpcEndpoint,
signer,
{
logger: new ConsoleLogger("debug")
}
);
Capture Error Details
Ensure you're capturing and logging full error details:
try {
// Your code
} catch (error) {
console.error("Detailed error:", {
message: error.message,
name: error.name,
stack: error.stack,
details: error.details || "no details",
data: error.data || "no data",
code: error.code || "no code"
});
}
Network Monitoring
Use browser developer tools to monitor network requests:
- Open your browser's developer tools (F12)
- Go to the Network tab
- Filter for XHR/Fetch requests
- Look for requests to RPC endpoints
- Examine request payloads and response data
Getting Help
If you encounter issues not covered in this document:
- Check the GitHub Issues (opens in a new tab) for similar problems
- Ask on the Cosmos Developer Discord (opens in a new tab) in the #developers channel
- For Telescope-specific help, reach out in the #telescope channel on Discord
- Submit an issue (opens in a new tab) with a complete description, including:
- Error messages
- Telescope version
- Node.js version
- Operating system
- Steps to reproduce the issue