DEV Community

Marcus Magalhães
Marcus Magalhães

Posted on

Error when running Next.js: "Cannot find module 'next/dist/compiled/ws'"

*When I try to run the npm run dev command, I get the following error:
*

[Error: Cannot find module 'next/dist/compiled/ws' Require stack:
  /mnt/c/Users/Marcus Flavio/OneDrive - Microsoft 365/Área de Trabalho/Projects/smartiming-pwa/node_modules/next/dist/server/dev/hot-reloader-webpack.js
  /mnt/c/Users/Marcus Flavio/OneDrive - Microsoft 365/Área de Trabalho/Projects/smartiming-pwa/node_modules/next/dist/server/lib/router-utils/setup-dev-bundler.js
  /mnt/c/Users/Marcus Flavio/OneDrive - Microsoft 365/Área de Trabalho/Projects/smartiming-pwa/node_modules/next/dist/server/lib/router-server.js
  /mnt/c/Users/Marcus Flavio/OneDrive - Microsoft 365/Área de Trabalho/Projects/smartiming-pwa/node_modules/next/dist/server/lib/start-server.js
] { code: 'MODULE_NOT_FOUND', requireStack: [Array] }

Enter fullscreen mode Exit fullscreen mode

*next.config.js file configuration:
*

const withPWA = require("@ducanh2912/next-pwa").default({
    dest: "public",
    cacheOnFrontEndNav: true,
    aggressiveFrontEndNavCaching: true,
    reloadOnOnline: true,
    swcMinify: true,
    disable: process.env.NODE_ENV === "development",
    workboxOptions: {
        disableDevLogs: true,
    },
    swSrc: "public/serviceWorker.js",
});

/** @type {import('next').NextConfig} */
const nextConfig = {
    typescript: {
        tsconfigPath: "./tsconfig.json",
    },
    images: {
        remotePatterns: [
            {
                protocol: "https",
                hostname: "**.**.**",
            },
        ],
    },

    webpack(config) {
        config.resolve.alias = {
            ...config.resolve.alias,
            "@": require("path").resolve(__dirname),
        };
        return config;
    },
};

module.exports = withPWA(nextConfig);

Enter fullscreen mode Exit fullscreen mode

Development environment
System: WSL on Windows
Node.js: v22.13.1
Next.js: v15.1.6

*Troubleshooting steps taken:
*

1- Added experimental configuration in next.config.js:

experimental: {
   outputFileTracingRoot: join(__dirname, '../../'),
}

Enter fullscreen mode Exit fullscreen mode

2- Cleared cache and removed temporary directories:

rm -rf .next && npm cache clean --force

Enter fullscreen mode Exit fullscreen mode

3- Removednode_modules andpackage-lock.jsonand reinstalled dependencies:

rm -rf node_modules package-lock.json
npm install

Enter fullscreen mode Exit fullscreen mode

*None of these solutions worked. Has anyone faced this error or has suggestions?
*

Top comments (1)

Collapse
 
gilles_ronco_33c721f2147e profile image
Gilles Ronco

No solution (Sorry).
I have same problem on Ubuntu 24.04 LTS with :
Node.js: v22.14.0
Next.js: v15.1.7
So interested if someone has an idea ...

NB : I am a Newbie on Node.js and Next.js

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →