When I try to run npm run dev
I get this 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]
}`
This is my next.config.js
file:
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);
I'm running my project within WSL on Windows Below are the versions of node js and Next js:
Node: v22.13.1 NextJs: Next.js v15.1.6
I was trying to run my Next.js project, but I encountered a 'MODULE_NOT_FOUND' error related to 'next/dist/compiled/ws'.
To fix this, I tried several solutions:
Added the following configuration in next.config.js
:
experimental: {
outputFileTracingRoot: join(__dirname, '../../'),
}
Cleared the cache using
rm -rf .next and npm cache clean --force.
Deleted node_modules and package-lock.json, then reinstalled dependencies with
npm install.
But nothing worked
When I try to run npm run dev
I get this 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]
}`
This is my next.config.js
file:
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);
I'm running my project within WSL on Windows Below are the versions of node js and Next js:
Node: v22.13.1 NextJs: Next.js v15.1.6
I was trying to run my Next.js project, but I encountered a 'MODULE_NOT_FOUND' error related to 'next/dist/compiled/ws'.
To fix this, I tried several solutions:
Added the following configuration in next.config.js
:
experimental: {
outputFileTracingRoot: join(__dirname, '../../'),
}
Cleared the cache using
rm -rf .next and npm cache clean --force.
Deleted node_modules and package-lock.json, then reinstalled dependencies with
npm install.
But nothing worked
Share Improve this question asked 5 hours ago Marcus-FlavioMarcus-Flavio 211 silver badge2 bronze badges New contributor Marcus-Flavio is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1 |1 Answer
Reset to default 0Just try all of these one by one :-
Try forcing a clean reinstall:
rm -rf node_modules package-lock.json .next
npm cache clean --force
npm install --legacy-peer-deps
npm rebuild
npm run dev
OR Manually install ws :
npm install ws --save-dev
I think there may be some nextjs version issue you are using so try to downgrade or upgrade :
OR Downgrade to Next.js 14 (stable)
npm install next@14
npm run dev
OR Upgrade Next.js
npm install next@latest
npm run dev
package-lock.json
andnode_modules
and runnpm i
? – Trusha Jadeja Commented 5 hours ago