Skip to content

webpack watch screwed up (v13.3.4 => v13.4.3) #50191

@jelmd

Description

@jelmd

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Node v18.16.0, Linux (Ubuntu 20.04), nextjs v13.4.3

Which area(s) of Next.js are affected? (leave empty if unsure)

Turbopack (--turbo)

Link to the code that reproduces this issue or a replay of the bug

https://nextjs.org/learn/basics/create-nextjs-app/setup

To Reproduce

  1. create a nextjs app
  2. make sure package.json dependencies contains "next": "13.4.3", e.g.
{
	"name": "foobar",
	"description": "Test",
	"repository": "https://github.com/x/y",
	"bugs": {
		"url": "https://github.com/x/y/issues"
	},
	"author": "Foo Bar <[email protected]>",
	"contributors": [],
	"version": "0.1.0",
	"private": true,
	"scripts": {
		"db": "NODE_OPTIONS='--no-warnings --loader ts-node/esm' nodemon --watch scripts scripts/db.ts",
		"dev": "next dev",
		"build": "next build",
		"start": "next start",
		"lint": "next lint",
		"clean": "rm -rf .next",
		"realclean": "rm -rf .next node_modules package-lock.json"
	},
	"dependencies": {
		"@next-auth/prisma-adapter": "^1.0.6",
		"@prisma/client": "^4.14.1",
		"next": "13.4.3",
		"nodemailer": "^6.9.2",
		"react": "18.2.0",
		"react-dom": "18.2.0"
	},
	"devDependencies": {
		"@styled-icons/material": "^10.47.0",
		"@styled-icons/fa-solid": "^10.47.0",
		"@types/busboy": "^1.5.0",
		"@types/node": "20.2.3",
		"@types/nodemailer": "^6.4.8",
		"@types/react": "18.2.6",
		"@types/react-dom": "18.2.4",
		"eslint": "8.41.0",
		"eslint-config-next": "13.4.3",
		"prisma": "^4.14.1",
		"typescript": "5.0.4"
	}
}
  1. add watchOptions for webpack to your next.config.js, e.g. the one used looks like this:
/** @type {import('next').NextConfig} */
const nextConfig = {
	reactStrictMode: true,
	webpack: function (config, options) {
		if (!config.watchOptions) {
			config.watchOptions = {
				aggregateTimeout: 5,
				ignored: [ '**/node_modules/**', '**/.git/**', '**/.next/**' ]
			};
		}
		return config;
	},
	experimental: {
		/* appDir: true, */
		instrumentationHook: true
	}
};
/*
process.on('unhandledRejection', error => {
	console.log('unhandledRejection', error);
});
*/
module.exports = nextConfig
  1. make sure, user watch settings has a reasonable value, i.e. 4-8K is even more than that (however, this seems to be the default on many systems)
    cat /proc/sys/fs/inotify/max_user_watches. If some one already screwed it up, use e.g. sysctl fs.inotify.max_user_watches=4096 to get it back to an acceptable value.
  2. run npm run dev

Describe the Bug

300+ K of error messages like this:

Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '~/work/nextapp/pages'
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '~/work/nextapp'
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '~/work'
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '~'
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home'
...

NOTE: The current working directory is ~/work/nextapp/ !!! Why does it want to monitor the whole user filesystem?

Expected Behavior

For nextjs v13.3.4 everything worked with the given configs as expected, i.e. no problems at all when running npm run dev (even if VScode is running side-by-side).

IMHO nextjs should pre-configure webpack etc. to monitor at most the current working directory and exclude by default ./node_modules (and possibly ./.next ?), because it is just a huge waste of resources for no (or not justifiable reason).

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformanceAnything with regards to Next.js performance.bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions