(React) Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath


Borislav Hadzhiev

Last updated: Apr 1, 2022


Photo from Unsplash

(React) Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath #

Run the npm update command to solve the "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath" and then run npm audit fix --force if necessary. The npm update command will update the installed modules that have fuzzy versioning.

package path not exported error

Open your terminal in your project's root directory (where your package.json file is) and run the following commands.

npm update npm audit fix --force

If the npm update command fails, run it with the --force flag as well.

npm update --force npm audit fix --force

The command respects semver and will update the packages with fuzzy version to the latest version and install missing packages.

The npm audit command scans your project for vulnerabilities and automatically installs compatible updates to vulnerable dependencies.

After you have ran the 2 commands, try restarting your development server.

If the error is not resolved, try to delete your node_modules and package-lock.json (not package.json) files, re-run npm install and restart your IDE.

# 👇️ delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # 👇️ clean npm cache npm cache clean --force npm install
Make sure to restart your IDE and dev server if the error still persists. VSCode often glitches and a reboot solves things sometimes.

The error happens often in React.js projects when issuing the npm start command and gets resolved after running npm update.

If that didn't help, try installing the @babel/helper-compilation-targets package as a development dependency.

Open your terminal in your project's root directory and run the following command:

# 👇️ with NPM npm install --save-dev @babel/helper-compilation-targets # ---------------------------------------------------------- # 👇️ with YARN yarn add @babel/helper-compilation-targets --dev

The @babel/helper-compilation-targets package works with browsers and Node.js and is used by @babel/preset-env to determine which plugin should be enabled based on the targeted environment.

If that didn't resolve your issue, run the node -v command and make sure you are running the long term supported version of Node.js.

You can issue the following command if you use nvm:

nvm install --lts

The command will install and switch to the long term supported version, which should resolve the issue.

The error often occurs when installing the latest version of Node, and rolling back to the long term supported version solves it.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.