Error: readdirp: root argument is required

Hi

My site is sharp-cray-fa6ab9. I’ve got a cryptic build error in Functions building:

Error: readdirp: root argument is required. Usage: readdirp(root, options)
Error location
10:31:06 AM:   During Functions bundling
10:31:06 AM:       at readdirp (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:262:11)
10:31:06 AM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:276:5
10:31:06 AM:       at new Promise (<anonymous>)
10:31:06 AM:       at Function.readdirpPromise [as promise] (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:274:10)
10:31:06 AM:       at hasFunctionRootFile (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:119:32)
10:31:06 AM:       at lacksNodeModules (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:111:12)
10:31:06 AM:       at getModuleNotFoundMessage (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:50:43)
10:31:06 AM:       at getModuleNotFoundErrorObject (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:41:25)
10:31:06 AM:       at getModuleNotFoundErrorFromZISI (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:91:10)
10:31:06 AM:       at getModuleNotFoundError (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:27:31)

How can I find which module was not found?

Welcome to the forums @potamus

Are you deploying a Next.js app?

Have a look at this post for a possible solution as well as this thread which @hrishikesh has been working on.

Also related is this thread.

No, I’m trying to deploy a svelte kit app.

Hi, @robhicks
I don’t know if this can help. I had a seemingly similar problem, though it was using Next.js, not svelte.

The problem in my case was that one of the functions executed on the backend to generate the static pages was using a library, knex (a database query builder), that was importing other commonjs dependencies (basically the drivers for different db flavours). I don’t fully understand the details but the problem solved when I added the following to my webpack configuration:

module.exports = {
  //...
  externals: ['mssql', 'mysql2', 'oracle', 'oracledb', 'postgres', 'redshift', 'sqlite3', 'pg', 'pg-query-stream', 'tedious', 
      { knex: 'commonjs knex' } ]

Except the { knex: 'commonjs knex' } part all the other modules are the drivers that knex can use but I don’t use. Some interaction between how knex is built, Next.js and the netlify next.js module was making webpack try to include those modules in the bundle while they are not even in my package.json.

Don’t know if this can help but perhaps gives you some tips about what may be happening in your case.

Thanks a lot. I added this to netlify.toml

[functions]
  node_bundler = "esbuild"

and it showed me the details, it was the pnpapi module. So I added it to my package.json and it solved the problem.

1 Like