You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trash() throws the following error when using Next.js on Windows: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of URL. Received an instance of URL at async deleteAction (./app/actions/delete.ts:14:5)
I've determined the issue is linked to what import.meta.url is returning in Next.js. In Next.js it looks like this "/_next/static/media/windows-trash.2b7fe177.exe". In the trash library the Windows trash binary is imported like this const binary = new URL('windows-trash.exe', import.meta.url);. Even though an URL is created, it fails later in a call to fileURLToPath() because it is missing a protocol (e.g. file:). fileURLToPath() validates the path using a isURL(path) there you can see it expects a protocol to be set.
trash()
throws the following error when using Next.js on Windows:TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of URL. Received an instance of URL at async deleteAction (./app/actions/delete.ts:14:5)
Reproducable example at https://github.com/kjetilhartveit/nextjs-sindresorhus-trash.
I've determined the issue is linked to what
import.meta.url
is returning in Next.js. In Next.js it looks like this "/_next/static/media/windows-trash.2b7fe177.exe". In the trash library the Windows trash binary is imported like thisconst binary = new URL('windows-trash.exe', import.meta.url);
. Even though an URL is created, it fails later in a call to fileURLToPath() because it is missing a protocol (e.g. file:).fileURLToPath()
validates the path using a isURL(path) there you can see it expects a protocol to be set.My temporary fix in my side-project has been to download the recycle-bin binary directly and then copied the logic from https://github.com/sindresorhus/trash/blob/main/lib/windows.js and https://github.com/sindresorhus/trash/blob/main/lib/chunked-exec.js except that the binary was "imported" like this
const pathToRecycleBinary = dirname(dirname(import.meta.url)) + "/binary/recycle-bin.exe";
Ala this:
I don't know if this is the best solution (importing the binary differently) to the problem though.
Note: not sure if this only affects Windows users
The text was updated successfully, but these errors were encountered: