# ThatOneBug - Full Content > Complete Markdown corpus of 8 developer error fixes from ThatOneBug (https://www.thatonebug.tech). Canonical index: https://www.thatonebug.tech/llms.txt Last generated: 2026-11-24T20:25:59.034Z Each entry below is a self-contained fix. Entries begin with YAML-style front matter identifying the canonical URL, category, and publication date. --- title: Fixing Error: invalid unicode code point at line 1 column 76631 url: https://www.thatonebug.tech/posts/nextjs-error-invalid-unicode-code-point-at-line-1-column-76631 category: Next.js published: 2026-11-24T04:59:09.705Z summary: This exception occurs when the Next.js build process or a runtime dependency attempts to parse a JSON string or JavaScript bundle containing an unescaped surrogate pair or an invalid UTF-8 sequence.... --- # Fixing Error: invalid unicode code point at line 1 column 76631 ## Problem Overview This exception occurs when the Next.js build process or a runtime dependency attempts to parse a JSON string or JavaScript bundle containing an unescaped surrogate pair or an invalid UTF-8 sequence. It is typically triggered by corrupted `node_modules`, stale `.next` cache artifacts, or non-ASCII characters in source files that were not properly encoded during the build pipeline. ## Root Cause - **Trigger**: A specific byte sequence at column 76631 of the compiled output (often `chunk.js` or `main.js`) contains a lone surrogate (e.g., `0xD800`–`0xDFFF`) or a control character that violates the JSON/JS specification. - **Runtime Behavior**: The V8 engine or the underlying JSON parser rejects the input because the Unicode code point is not a valid scalar value. This often happens when a dependency package ships with malformed data or when the local file system encoding (e.g., Windows-1252 vs. UTF-8) corrupts multi-byte characters during the `npm install` or `next build` phase. ## Step-by-Step Fix ### Step 1: Diagnose the State Identify the specific file and character causing the failure by inspecting the build output and checking for non-ASCII characters in the source tree: ```bash # Locate the specific chunk file mentioned in the full stack trace find .next -name "*.js" -exec grep -l "invalid unicode" {} \; # Check for non-UTF8 characters in source files (Linux/Mac) LC_ALL=C grep -P "[^\x00-\x7F]" src/**/*.js src/**/*.json 2>/dev/null || echo "No non-ASCII found in src" # Verify Node.js version compatibility node -v ``` ### Step 2: Apply the Fix Clear the corrupted cache and reinstall dependencies to ensure all packages are fetched with correct encoding. If the issue persists in a specific dependency, patch the file or update the package: ```bash # 1. Remove build artifacts and lockfile rm -rf .next rm -rf node_modules rm package-lock.json # 2. Reinstall dependencies with forced UTF-8 handling npm install --force # 3. If the error persists, identify the offending package and patch it # Example: If 'some-lib' is the culprit, use npx patch-package npx patch-package some-lib # 4. Rebuild npm run build ``` ### Step 3: Verify the Resolution Confirm the build completes without Unicode errors and the application serves correctly: ```bash # Run the production build npm run build # Start the production server and check for 200 OK npm start & curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 ``` ## Prevention - Enforce UTF-8 encoding in your editor and CI/CD pipelines (e.g., `export LC_ALL=C.UTF-8`). - Add a pre-commit hook using `husky` and `lint-staged` to reject files containing invalid Unicode sequences. - Pin dependency versions in `package.json` to avoid pulling in a new release of a library that introduces malformed data. - Use `next.config.js` to configure `output: 'standalone'` if deploying to Docker, ensuring a clean, self-contained bundle that avoids host file system encoding issues. Source: https://www.thatonebug.tech/posts/nextjs-error-invalid-unicode-code-point-at-line-1-column-76631 --- title: Fixing Module not found: Can't resolve 'react': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-module-not-found-cant-resolve-react category: Next.js published: 2026-11-09T05:30:30.411Z summary: This exception occurs when the Next.js build process or runtime cannot locate the `react` package within the `node_modules` directory or the configured module resolution paths. It is typically... --- # Fixing Module not found: Can't resolve 'react': Root Cause and Resolution ## Problem Overview This exception occurs when the Next.js build process or runtime cannot locate the `react` package within the `node_modules` directory or the configured module resolution paths. It is typically triggered by a missing dependency installation, a corrupted `node_modules` state, or a mismatch between the `react` and `react-dom` versions. ## Root Cause - **Trigger**: The `react` package is absent from the project's `node_modules` directory, or the `package.json` does not list `react` as a direct dependency. - **Runtime Behavior**: The Webpack or Turbopack bundler attempts to resolve the import statement `import React from 'react'` (or implicit imports within Next.js internal components). When the module resolver fails to find the package entry point, it throws a `ModuleNotFoundError` with code `MODULE_NOT_FOUND`. ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash ls node_modules/react/package.json cat package.json | grep -E '"react"|"react-dom"' ``` ### Step 2: Apply the Fix Provide the exact code patch, configuration change, or dependency update: ```bash npm install react react-dom ``` ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash npm run build ``` ## Prevention - Ensure `react` and `react-dom` are listed in the `dependencies` section of `package.json`. - Maintain version parity between `react` and `react-dom` to prevent peer dependency conflicts. - Avoid manually deleting `node_modules` without re-running the package manager's install command. - Use a lockfile (`package-lock.json` or `yarn.lock`) to ensure consistent dependency resolution across environments. Source: https://www.thatonebug.tech/posts/nextjs-module-not-found-cant-resolve-react --- title: Fixing Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-nextdistserverfutureroute-modulespagesvendoredcontextshead-manager-context category: Next.js published: 2026-11-05T05:30:37.744Z summary: This exception occurs when the Node.js runtime attempts to resolve internal Next.js server-side rendering (SSR) context modules that do not exist in the installed version of the framework. It is... --- # Fixing Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context': Root Cause and Resolution ## Problem Overview This exception occurs when the Node.js runtime attempts to resolve internal Next.js server-side rendering (SSR) context modules that do not exist in the installed version of the framework. It is triggered by a version mismatch between the `next` package and `@next/react` or custom server implementations, or by stale build artifacts referencing deprecated internal paths. ## Root Cause - **Trigger**: The application code or a dependency explicitly imports `next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context`. This path was removed or renamed in Next.js 13.4+ and 14.x as the internal architecture shifted from "future" route modules to stable implementations. - **Runtime Behavior**: Node.js module resolution fails because the file path does not exist in the `node_modules/next` directory structure of the installed version. The bundler (Webpack/Turbopack) or the SSR runtime throws a `MODULE_NOT_FOUND` error during the hydration or server component evaluation phase. ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash # Check installed Next.js version and verify if the path exists cat node_modules/next/package.json | grep '"version"' ls -la node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/ 2>/dev/null || echo "Path does not exist" ``` ### Step 2: Apply the Fix Provide the exact code patch, configuration change, or dependency update: ```bash # 1. Clear cache and node_modules to remove stale references rm -rf .next node_modules # 2. Reinstall dependencies with exact versions npm install # 3. If using custom server.js or middleware, replace the invalid import # Old (Invalid): # import { HeadManagerContext } from 'next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context' # # New (Valid): # import { HeadManagerContext } from 'next/dist/shared/lib/head-manager-context' # OR # import { HeadManagerContext } from 'next/dist/shared/lib/head-manager-context.js' # 4. Rebuild the application npm run build ``` ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash # Start the development server and check for module resolution errors npm run dev # In a separate terminal, verify the server responds without 500 errors curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 ``` ## Prevention - Avoid importing from `next/dist/` internal paths unless explicitly documented in the Next.js API reference. - Pin `next` and `@next/react` versions in `package.json` to prevent accidental major version upgrades that break internal module structures. - Use `next lint` and TypeScript strict mode to catch invalid module imports during development. - Clear `.next` cache after any major dependency update to prevent stale build artifacts from referencing removed files. Source: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-nextdistserverfutureroute-modulespagesvendoredcontextshead-manager-context --- title: Fixing Cannot find module '@next/react-refresh-utils': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-nextreact-refresh-utils category: Next.js published: 2026-10-29T05:30:35.165Z summary: This exception occurs when the Next.js development server attempts to load the React Fast Refresh runtime but fails to resolve the internal `@next/react-refresh-utils` package. It is typically... --- # Fixing Cannot find module '@next/react-refresh-utils': Root Cause and Resolution ## Problem Overview This exception occurs when the Next.js development server attempts to load the React Fast Refresh runtime but fails to resolve the internal `@next/react-refresh-utils` package. It is typically triggered by a corrupted `node_modules` directory, a version mismatch between `next` and `react`, or an incomplete installation following a manual dependency update. ## Root Cause - **Trigger**: The `next` package version is out of sync with the installed `react` and `react-dom` versions, or the `node_modules` tree is missing internal scoped packages due to a failed `npm install` or `yarn` execution. - **Runtime Behavior**: During the initialization of the development server, Next.js injects the React Refresh runtime. The module resolver searches for `@next/react-refresh-utils` within the `next` package's internal dependencies. If the file structure is incomplete or the version hash does not match the expected internal API, the Node.js `require` call throws a `MODULE_NOT_FOUND` error. ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash npm ls next react react-dom ``` Check for `invalid` or `UNMET` dependencies. Additionally, verify the existence of the specific module: ```bash ls node_modules/next/dist/build/webpack/plugins/react-refresh-utils.js ``` ### Step 2: Apply the Fix Clear the dependency cache and reinstall all packages to ensure a consistent tree structure. Use the package manager appropriate for your project: ```bash # For npm rm -rf node_modules package-lock.json npm install # For yarn rm -rf node_modules yarn.lock yarn install # For pnpm rm -rf node_modules pnpm-lock.yaml pnpm install ``` If the error persists, explicitly align the `next` version with the supported React version. For Next.js 13/14, ensure `react` and `react-dom` are at version `18.2.0` or higher: ```bash npm install next@latest react@18.2.0 react-dom@18.2.0 ``` ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash npm run dev ``` The development server should start without throwing the `Cannot find module` exception. Verify the module resolution explicitly: ```bash node -e "require('@next/react-refresh-utils'); console.log('Module resolved successfully')" ``` ## Prevention - Avoid manually editing `package.json` to update `next` without running a full dependency resolution (`npm install` or `yarn`). - Pin `react` and `react-dom` versions in `package.json` to prevent accidental major version upgrades that may break internal Next.js dependencies. - Use `npm ci` in CI/CD pipelines to ensure an exact match with the lockfile, preventing drift in internal scoped packages. - Clear the Next.js cache (`node_modules/.cache`) if the error appears after a code change but not after a fresh install. Source: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-nextreact-refresh-utils --- title: Fixing Cannot find module 'next/dist/shared/lib/router/utils/routing-items.js': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-nextdistsharedlibrouterutilsrouting-itemsjs category: Next.js published: 2026-10-19T05:30:43.720Z summary: This exception occurs when the Next.js runtime attempts to resolve internal router utilities that do not exist in the installed version of the `next` package. It is typically triggered by a version... --- # Fixing Cannot find module 'next/dist/shared/lib/router/utils/routing-items.js': Root Cause and Resolution ## Problem Overview This exception occurs when the Next.js runtime attempts to resolve internal router utilities that do not exist in the installed version of the `next` package. It is typically triggered by a version mismatch between the `next` dependency and the `@next/react-dev-overlay` or `@next/font` packages, or by a corrupted `node_modules` directory following a partial installation. ## Root Cause - **Trigger**: The `next` package version in `package.json` does not match the actual files present in `node_modules/next/dist/shared/lib/router/utils/`. Specifically, `routing-items.js` was introduced or renamed in specific Next.js versions (e.g., v13.4+ or v14.x), but the installed binary tree is from an older or incompatible version. - **Runtime Behavior**: The Node.js module resolver (`require` or `import`) fails to locate the file path within the `next` package's distribution folder. This causes an immediate `MODULE_NOT_FOUND` error during the server startup or client-side hydration phase, halting the application process. ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash npm ls next ``` Verify that the installed version matches the version specified in `package.json`. If the output shows `UNMET DEPENDENCY` or a version mismatch, proceed to Step 2. ### Step 2: Apply the Fix Clear the local cache and reinstall dependencies to ensure a consistent module tree. Execute the following commands in sequence: ```bash rm -rf node_modules rm -rf .next npm cache clean --force npm install ``` If using Yarn or pnpm, replace `npm install` with `yarn install` or `pnpm install` respectively. ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash npm run dev ``` The development server should start without throwing the `MODULE_NOT_FOUND` error. Access the application in the browser to ensure the router initializes correctly. ## Prevention - Pin the `next` version in `package.json` to avoid unintended major version upgrades during `npm update`. - Use a lockfile (`package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml`) and commit it to version control to ensure reproducible builds. - Avoid manually editing files within `node_modules/next/dist/`. All internal changes must be managed through the `next` package version. - When upgrading Next.js, review the migration guide for breaking changes in internal module paths and update any direct imports of `next/dist` modules accordingly. Source: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-nextdistsharedlibrouterutilsrouting-itemsjs --- title: Fixing Cannot find module 'next/dist/compiled/ws': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-cannot-find-module-nextdistcompiledws category: Next.js published: 2026-10-12T05:30:29.654Z summary: This exception occurs when the Next.js development server or build process attempts to import the WebSocket library from the internal `next/dist/compiled` directory, but the file is missing or... --- # Fixing Cannot find module 'next/dist/compiled/ws': Root Cause and Resolution ## Problem Overview This exception occurs when the Next.js development server or build process attempts to import the WebSocket library from the internal `next/dist/compiled` directory, but the file is missing or corrupted. It is typically triggered by a failed `npm install`, a partial `node_modules` deletion, or a version mismatch between the `next` package and its internal dependencies. ## Root Cause - **Trigger**: The `next` package's internal dependency resolution fails to locate `next/dist/compiled/ws/index.js`. This often happens when `node_modules` is in an inconsistent state due to interrupted installations or cache corruption. - **Runtime Behavior**: Node.js module resolution traverses the `node_modules` tree. When the specific path `next/dist/compiled/ws` does not exist on the filesystem, the `require` or `import` statement throws a `MODULE_NOT_FOUND` error, halting the server startup or build process. ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash ls -la node_modules/next/dist/compiled/ws ``` If the directory or `index.js` file is missing, the installation is corrupted. Additionally, check the installed version: ```bash npm list next ``` ### Step 2: Apply the Fix Clear the local cache and reinstall dependencies to restore the missing internal files: ```bash rm -rf node_modules package-lock.json npm cache clean --force npm install ``` If using Yarn: ```bash rm -rf node_modules yarn.lock yarn cache clean yarn install ``` ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash ls node_modules/next/dist/compiled/ws/index.js npm run dev ``` The development server should start without throwing the `MODULE_NOT_FOUND` error. ## Prevention - Avoid manually deleting files within `node_modules` unless necessary. - Ensure `package-lock.json` or `yarn.lock` is committed to version control to maintain dependency consistency across environments. - Use a consistent Node.js version across all development and CI/CD environments, verified via `.nvmrc` or `engines` field in `package.json`. - Clear the Next.js cache (`.next` directory) if build artifacts persist after dependency updates: `rm -rf .next`. Source: https://www.thatonebug.tech/posts/nextjs-cannot-find-module-nextdistcompiledws --- title: Fixing Cannot find module 'setprototypeof': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-setprototypeof category: Next.js published: 2026-10-08T05:31:43.623Z summary: This exception occurs when the Node.js module resolution algorithm fails to locate the `setprototypeof` package within the `node_modules` directory, typically due to a corrupted installation, missing... --- # Fixing Cannot find module 'setprototypeof': Root Cause and Resolution ## Problem Overview This exception occurs when the Node.js module resolution algorithm fails to locate the `setprototypeof` package within the `node_modules` directory, typically due to a corrupted installation, missing transitive dependency, or version mismatch between `express` and its underlying `setprototypeof` requirement. ## Root Cause - **Trigger**: A missing or corrupted `node_modules` directory, an incomplete `npm install` execution, or a lockfile (`package-lock.json`) that does not match the current `package.json` dependencies. - **Runtime Behavior**: The CommonJS loader (`require()`) throws a `MODULE_NOT_FOUND` error because the path resolution for `setprototypeof` (a dependency of `express`/`send`) fails to resolve to a valid file system path. ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash ls node_modules/setprototypeof ``` ### Step 2: Apply the Fix Provide the exact code patch, configuration change, or dependency update: ```bash rm -rf node_modules package-lock.json npm install ``` ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash node -e "require('setprototypeof')" && echo "Module loaded successfully" ``` ## Prevention - Always commit `package-lock.json` to version control to ensure deterministic dependency resolution across environments. - Avoid manually deleting individual packages from `node_modules`; use `npm uninstall` or `npm install` to manage the dependency tree. - Pin specific versions of `express` and `setprototypeof` in `package.json` if transitive dependency updates cause breaking changes. Source: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-setprototypeof --- title: Fixing Error: Cannot find module 'next': Root Cause and Resolution url: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-next category: Next.js published: 2026-10-07T18:45:57.716Z summary: This exception occurs when the Node.js runtime cannot resolve the `next` package within the `node_modules` directory. It is typically triggered by incomplete installations, corrupted dependency... --- # Fixing Error: Cannot find module 'next': Root Cause and Resolution ## Problem Overview This exception occurs when the Node.js runtime cannot resolve the `next` package within the `node_modules` directory. It is typically triggered by incomplete installations, corrupted dependency trees, or mismatched lockfiles in the project root. ## Root Cause - **Trigger**: Missing `node_modules` directory, failed `npm install`/`yarn install` execution, or a stale `package-lock.json`/`yarn.lock` that conflicts with the current `package.json` dependencies. - **Runtime Behavior**: The Node.js module resolution algorithm traverses up the directory tree from the entry point. When it fails to locate the `next` package identifier in any parent `node_modules` folder, it throws `MODULE_NOT_FOUND` (Error: Cannot find module 'next'). ## Step-by-Step Fix ### Step 1: Diagnose the State Run the following command in your terminal to inspect the environment: ```bash ls -la node_modules/next cat package.json | grep -A 5 '"dependencies"' ``` ### Step 2: Apply the Fix Provide the exact code patch, configuration change, or dependency update: ```bash rm -rf node_modules package-lock.json npm install ``` ### Step 3: Verify the Resolution Confirm the fix worked by running: ```bash npx next --version npm run dev ``` ## Prevention - Commit `package-lock.json` or `yarn.lock` to version control to ensure deterministic dependency resolution across environments. - Avoid manually editing `node_modules` or `package.json` without running the package manager's install command. - Use a consistent Node.js version across development and CI/CD pipelines via `.nvmrc` or `engines` field in `package.json`. Source: https://www.thatonebug.tech/posts/nextjs-error-cannot-find-module-next