node.jstypescriptpackagehadoop-yarnnvm

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader


I get the following error when trying to run yarn dev to launch a discord bot. I am using typescript. I have already tried using nvm to update the node js version. I even tried using lower versions of node.js all the way down to 16.20.2 with no success. I have the redis server running to the point where I use the redis-cli and it returns back with a PONG.

node:events:493
      throw er; // Unhandled 'error' event
      ^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:236:11)
    at defaultLoad (node:internal/modules/esm/load:128:3)
    at nextLoad (node:internal/modules/esm/hooks:749:28)
    at Z (file:///C:/Users/MSI/Documents/GitHub/steadfast-scrim/node_modules/tsx/dist/esm/index.mjs:13:1655)
    at nextLoad (node:internal/modules/esm/hooks:749:28)
    at Hooks.load (node:internal/modules/esm/hooks:382:26)
    at handleMessage (node:internal/modules/esm/worker:199:24)
    at checkForMessages (node:internal/modules/esm/worker:141:28)
    at process.<anonymous> (node:internal/modules/esm/worker:160:5)
    at process.emit (node:events:515:28) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Node.js v21.1.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

And if this helps the whole github respository is here


Solution

  • So what I did to fix the error was add "type": "module", into the package.json file.