Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports' [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
4 min

banner

# Table of Contents

  1. Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'
  2. [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath 'v4' is not defined by "exports"
If you got the error 'Package subpath 'v4' is not defined by "exports"' when using the uuid module, click on the second subheading.

# 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

shell
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/parser' is not defined by "exports" in

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

issue npm update

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

shell
npm update --force npm audit fix --force

issue npm update with force flag

The command respects semver. It updates the packages with a fuzzy version to the latest version and installs missing packages.

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

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

# Delete your node_modules and reinstall your dependencies

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.

If you are on macOS or Linux, issue the following commands in bash or zsh.

shell
# for macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install

If you are on Windows, issue the following commands in CMD.

cmd
# for Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install

Make sure to restart your IDE and dev server if the error persists. VSCode often glitches and needs a reboot.

The error happens often in Next.js projects when issuing the npm run dev command and gets resolved after running npm update.

# Install the @babel/helper-compilation-targets package

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

install babel helper compilation targets

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.

# Use the long-term supported version of Node.js

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.

If you use nvm, you can update your version of Node.js and npm with the following 2 commands.

shell
nvm install --lts nvm use --lts

install lts node js version

Want to learn more about installing and using NVM? Check out these resources: Install NVM on macOS and Linux,Install NVM on Windows.

You can also use the n package to manage your Node.js version.

shell
npm cache clean -f npm install -g n n stable

If you get a permissions error when issuing the commands, open CMD as an administrator (Windows) or prefix the commands with sudo (macOS and Linux).

shell
sudo npm cache clean -f sudo npm install -g n sudo n stable

Alternatively, you can download the long-term supported version of Node.js from the official nodejs.org website.

The error often occurs when installing the latest version of Node. Rolling back to the long-term supported version solves it.

# [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath 'v4' is not defined by "exports"

The error '[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports"' occurs because the uuid module removed the option to import from a subpath in version 8.

To solve the error, import directly from the uuid module.

err package path not exported package subpath v4 is not defined

Here is an example of how the error occurs.

index.js
// โ›”๏ธ Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports" in /home/borislav/Desktop/bobbyhadz-rest/bobbyhadz-js/node_modules/uuid/package.json imported from /home/borislav/Desktop/bobbyhadz-rest/bobbyhadz-js/index.js import uuidv4 from 'uuid/v4'; // ๐Ÿ‘ˆ๏ธ importing from subpath console.log(uuidv4);

We import from a subpath instead of importing directly from the uuid module.

First, make sure you have the uuid module installed.

# Install the uuid module

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

shell
# ๐Ÿ‘‡๏ธ with NPM npm install uuid # ๐Ÿ‘‡๏ธ Only if you use TypeScript npm install --save-dev @types/uuid # ----------------------------------------------- # ๐Ÿ‘‡๏ธ with YARN yarn add uuid # ๐Ÿ‘‡๏ธ Only if you use TypeScript yarn add @types/uuid --dev

Now you should be able to import directly from the uuid module.

If you use ES6 module import/export syntax, use the following import statement.

index.js
import {v4 as uuidv4} from 'uuid'; console.log(uuidv4()); // ๐Ÿ‘‰๏ธ dcc5b637-9760-4a7a-bba0-f50afdf9b0bb

We import the v4 function from the uuid module and alias it to uuidv4.

If you use the older CommonJS syntax, import as follows.

index.js
const {v4: uuidv4} = require('uuid'); console.log(uuidv4()); // ๐Ÿ‘‰๏ธ 50b78e3b-705b-49c4-94ba-a337c637a651

We import the v4 function from the uuid module and alias it to uuidv4.

If you use the require syntax, you can also import the entire uuid module and access the v4() method on the module.

index.js
const uuid = require('uuid'); console.log(uuid.v4()); // ๐Ÿ‘‰๏ธ 3c5b1d42-bf23-4340-8227-2e4a95586747

However, you can't use this approach when using the ES6 module import/export syntax because the uuid module doesn't have a default export.

Alternatively, you can import the v4 method using a named import without aliasing it.

index.js
import {v4} from 'uuid'; console.log(v4()); // ๐Ÿ‘‰๏ธ 3218f006-8861-416a-b9b6-d16f9f06b7d6

# Delete your node_modules and reinstall your dependencies

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
# ๐Ÿ‘‡๏ธ Windows - delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json # ๐Ÿ‘‡๏ธ macOS/Linux - delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force npm install

Make sure to restart your IDE and dev server if the error persists. VSCode often glitches and needs a reboot.

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.

Copyright ยฉ 2024 Borislav Hadzhiev