Solve - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'

avatar

Borislav Hadzhiev

Wed Apr 06 20222 min read

banner

Photo by Jeremy Bishop

Solve - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports' #

Run the npm update command to solve the "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'" 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.

shell
npm update npm audit fix --force

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

shell
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.

shell
# 👇️ 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 Next.js projects when issuing the npm run dev 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:

shell
# 👇️ 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:

shell
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.

Use the search field on my Home Page to filter through my more than 1,000 articles.