Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GuessPlugin
✓ import { GuessPlugin } from 'guess-webpack';
✗ const GuessPlugin = require('guess-webpack').default;
While the README shows CommonJS `require`, modern TypeScript/ESM projects should use named `import`.
GuessPlugin (CJS)
✓ const { GuessPlugin } = require('guess-webpack');
Standard CommonJS import pattern as shown in the README for Node.js environments.
guess
✓ import { guess } from 'guess-webpack/api';
✗ import guess from 'guess-webpack/api';
The `guess` function is a named export from a specific subpath, not a default export.
parseRoutes
✓ import { parseRoutes } from 'guess-parser';
✗ import { parseRoutes } from 'guess-webpack';
Note that `parseRoutes` is imported from the separate `guess-parser` package, not `guess-webpack` directly.
Configures `GuessPlugin` in `webpack.config.js` to enable analytics-driven bundling and demonstrates the runtime usage of the `guess` function for predictive prefetching based on current or specified routes.
import path from 'path';
import { GuessPlugin } from 'guess-webpack';
// webpack.config.js
// Assumes you have 'webpack' and 'webpack-cli' installed as dev dependencies
// and a 'package.json' initialized.
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/' // Important for route recognition
},
plugins: [
new GuessPlugin({
// Replace 'GOOGLE_ANALYTICS_VIEW_ID' with your actual GA View ID
// For local development, you might mock this or use test data.
GA: process.env.GOOGLE_ANALYTICS_VIEW_ID ?? 'UA-XXXXX-Y',
// Example with JWT for server-side auth (optional)
// jwt: require('./credentials.json'),
// Example routeProvider for automatic prefetching (requires 'guess-parser')
// For many React/Vue apps, custom mapping might be needed.
// For this quickstart, we omit `routeProvider` to keep it simple,
// relying on manual `guess()` calls at runtime.
runtime: {
delegate: false // Delegate to framework-specific prefetching if available
}
})
],
devServer: {
static: './dist',
historyApiFallback: true // Important for SPA routing
}
};
// src/index.js (simplified application entry point)
import { guess } from 'guess-webpack/api';
console.log('Application started.');
// Simulate a route change or initial load
function simulateNavigation(currentRoute = '/') {
const predictions = guess(currentRoute);
console.log(`From ${currentRoute}, likely next pages:`, predictions);
// In a real app, you would use 'predictions' to prefetch bundles
// For example, fetch(predictions[0].url);
}
// Call on initial load
simulateNavigation();
// Simulate navigation after a delay
setTimeout(() => {
simulateNavigation('/foo');
}, 3000);
// This quickstart demonstrates configuring the GuessPlugin in webpack
// and using the runtime `guess` function to get predictions for prefetching.
Errors
Common errors & fixes
Error: GA_VIEW_ID is required for GuessPlugin configuration.
The `GA` option in `GuessPlugin` was omitted or set to an invalid value, preventing Google Analytics data from being fetched.
fixProvide a valid Google Analytics View ID to the `GA` property in your `GuessPlugin` configuration: `new GuessPlugin({ GA: 'UA-XXXXX-Y' })`. TypeError: guess is not a function
The `guess` function was imported incorrectly (e.g., as a default import or from the wrong path).
fixEnsure `guess` is imported as a named export from `guess-webpack/api`: `import { guess } from 'guess-webpack/api';` Error: Failed to fetch Google Analytics data. Check credentials.
Authentication to the Google Analytics API failed, possibly due to incorrect JWT credentials or issues with OAuth2 setup.
fixVerify your `jwt` credentials file (e.g., `credentials.json`) is correct and accessible, or ensure your OAuth2 authentication flow is properly configured and authorized.
Module not found: Error: Can't resolve 'guess-parser'
The `guess-parser` package is used by `GuessPlugin` for automatic route parsing but is not installed as a dependency.
fixInstall `guess-parser` as a development dependency: `npm install --save-dev guess-parser`.
Audit
Dependencies
webpackrequiredCore peer dependency as it is a webpack plugin. Requires webpack >= 4.37.0.
webpack-clioptionalRecommended for running webpack from the command line, especially with webpack v4 and later.
guess-gaoptionalUsed by GuessPlugin for fetching structured data from the Google Analytics API to learn about user navigation patterns.
guess-parseroptionalUsed by GuessPlugin for parsing applications to create mappings between routes and JavaScript bundles, especially for automatic prefetching.