Search code examples
node.jsaxiosvirtual-reality

Using require axios and vrchat, I get "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]. Package subpath '. /lib/defaults'" error


In Node.js I wrote:

const axios = require("axios");
const vrchat = require("vrchat");

Here's the full error message:

node:internal/modules/cjs/loader:571
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/defaults' is not defined by "exports" in /Users/owner/vrchat_api/node_modules/axios/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:697:9)
    at resolveExports (node:internal/modules/cjs/loader:565:36)
    at Module._findPath (node:internal/modules/cjs/loader:634:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/Users/owner/vrchat_api/node_modules/axios-cookiejar-support/lib/index.js:8:40) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v18.14.2

Curiously, the following code does not generate an error.

const axios = require("axios");

I have removed package-lock.json and node_modules and npm install and get the same error.

How does one resolve it?


Solution

  • This error usually occurs when there is a mismatch between the version of the axios package and the version of Node.js being used.

    You can try updating your Node.js version to the latest stable version and then reinstalling the axios package.

    Alternatively, you can try using an older version of the axios package that is compatible with your current version of Node.js.

    To do this, you can uninstall the current version of axios using the following command:

    npm uninstall axios
    

    Then, install an older version of axios using the following command:

    npm install [email protected]
    

    Replace 0.19.2 with the version that is compatible with your current version of Node.js.

    Once you have installed the compatible version of axios, try running your code again and see if the error persists.