Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in the package.json of a module in node_modules

ReactjsNpmNode Modulespackage.jsonPostcss

Reactjs Problem Overview


This is a React web app. When I run

npm start

This error occurred

> dataflow@0.1.0 start
> react-scripts start

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

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /Users/juliantc/Desktop/ai-studio/development/frontend/node_modules/postcss-safe-parser/node_modules/postcss/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:416:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:669:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/juliantc/Desktop/ai-    studio/development/frontend/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v17.0.1

This error only occurs when I run this on this specific computer, which I do not have superuser access to. It works on other computers.

For reference, this is ./node_modules/postcss-safe-parser/node_modules/postcss/package.json

{
  "name": "postcss",
  "version": "8.2.6",
  "description": "Tool for transforming styles with JS plugins",
  "engines": {
    "node": "^10 || ^12 || >=14"
  },
  "exports": {
    ".": {
      "require": "./lib/postcss.js",
      "import": "./lib/postcss.mjs",
      "types": "./lib/postcss.d.ts"
    },
    "./": "./"
  },
  "main": "./lib/postcss.js",
  "types": "./lib/postcss.d.ts",
  "keywords": [
    "css",
    "postcss",
    "rework",
    "preprocessor",
    "parser",
    "source map",
    "transform",
    "manipulation",
    "transpiler"
  ],
  "funding": {
    "type": "opencollective",
    "url": "https://opencollective.com/postcss/"
  },
  "author": "Andrey Sitnik <[email protected]>",
  "license": "MIT",
  "homepage": "https://postcss.org/",
  "repository": "postcss/postcss",
  "dependencies": {
    "colorette": "^1.2.1",
    "nanoid": "^3.1.20",
    "source-map": "^0.6.1"
  },
  "browser": {
    "./lib/terminal-highlight": false,
    "colorette": false,
    "fs": false
  }
}

And this is what I get when I list the files in ./node_modules/postcss-safe-parser/node_modules/postcss/lib/

lgtd-lt-119-mbmt:frontend juliantc$ ls ./node_modules/postcss-safe-parser/node_modules/postcss/lib/

at-rule.d.ts		css-syntax-error.d.ts	input.d.ts		map-generator.js	postcss.d.ts		processor.js		rule.js			tokenize.js
at-rule.js		css-syntax-error.js	input.js		node.d.ts		postcss.js		result.d.ts		stringifier.js		warn-once.js
comment.d.ts		declaration.d.ts	lazy-result.d.ts	node.js			postcss.mjs		result.js		stringify.d.ts		warning.d.ts
comment.js		declaration.js		lazy-result.js		parse.d.ts		previous-map.d.ts	root.d.ts		stringify.js		warning.js
container.d.ts		fromJSON.d.ts		list.d.ts		parse.js		previous-map.js		root.js			symbols.js
container.js		fromJSON.js		list.js			parser.js		processor.d.ts		rule.d.ts		terminal-highlight.js

Reactjs Solutions


Solution 1 - Reactjs

I am also stuck with the same problem because I installed the latest version of Node.js (v17.0.1).

Just go for node.js v14.18.1 and remove the latest version just use the stable version v14.18.1

nvm uninstall <version>

OR

nvm uninstall v17.0.1

then install the LTS one which is v14.18.1

nvm install --lts

This worked for me.

Solution 2 - Reactjs

Remove node_modules folder and .lock file and re-install your packages (yarn or npm). It worked for me with last 17.0.1 of nodejs, I can npm (or yarn) start my app again.

Solution 3 - Reactjs

Roll back to Node 16.8.0 or (works for me) stable version 16.13.0:

Step 1: install n

npm install -g n

Step 2: install/set node latest stable version

sudo n stable

or set 16.8.0

sudo n 16.8.0

Note, if you can't or don't want to use sudo for n, you can set environment variables for the location, eg;

export N_PREFIX=$HOME/.n
export PATH=$N_PREFIX/bin:$PATH

Solution 4 - Reactjs

FWIW, I bumped into this issue on macOS Monterey with Node 17.0.1 installed via Homebrew. Downgrading to Node 16.x worked for me.

Downgrade from Node 17.x (latest) to Node 16.x using Homebrew:

brew uninstall --ignore-dependencies node
brew install node@16
brew link node@16

Solution 5 - Reactjs

my working solution was with yarn:

  • removed /node_modules and yarn.lock file.
  • then reinstalled my deleted packages/file using yarn install .

it worked !!!

Solution 6 - Reactjs

removing and reinstalling lock and node modules didn't help but npm update worked for me

Solution 7 - Reactjs

I also get the error when using Node.js v17.0.1 (Lates Features) - I am using macOS Catalina and homebrew.

So I want to switch Node.js v17.0.1 to Node.js (LTS) -> Node.js v16.3.1

I uninstall node using homebrew with the following command:

brew uninstall node

Then I download Node LTS from https://nodejs.org/en/ and install it.

enter image description here

That is work for me. Thanks :)

Solution 8 - Reactjs

After removing node_modules & package-lock.json, I ran

npm audit fix --force 

& updated react-scripts to the latest available version with

npm install react-scripts@latest

Solution 9 - Reactjs

I just did:

npm update
npm start

worked for me.

Solution 10 - Reactjs

Remove node_module & package-lock.json

then

npm install 

( in install if you get error as to use --force and --legacy-peer-deps the command as

`npm install --legacy-peer-deps`

)

npm start

Solution 11 - Reactjs

An update to the latest version of "react-scripts" have been worked for me! Previous "react-scripts" version was 4.0.3 and I've updated to 5.0.0. Node version is 17.0.1.

Solution 12 - Reactjs

If you use yarn you can:

rm -rf node_modules yarn.lock
yarn add -D react-scripts@latest
yarn build

For npm:

rm -rf node_modules package-lock.json
npm install -D react-scripts@latest
npm install
npm run build

Solution 13 - Reactjs

I faced similar issue and it was due to node version v17.1.0.

I have nvm with 3 different versions of node installed. Just switched to version v14.18.1 using nvm and the issue resolved.

Solution 14 - Reactjs

I was receiving Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/parser' is not defined by "exports" in ...node_modules\next\node_modules\postcss\package.json

I have resolved it on node version 17.4.0 after I upgraded react, and nextjs using:

npm install react@latest react-dom@latest
npm install next@12

(https://nextjs.org/docs/upgrading)

Solution 15 - Reactjs

Uninstalling the current Node.js and installing LTS solves the problem, but if you want to keep the currently installed version, you could use nvs add lts to install the latest Node.js LTS, and activate it using nvs use node/<lts version>/<platform>. The LTS version and Platform values will be provided in the first command output.

Solution 16 - Reactjs

I don't get why @AnmolNoor wants you to uninstall version 17.

The proper way:

  1. Make sure you have nvm (https://github.com/nvm-sh/nvm). If you don't, I highly recommend installing it.

  2. Check your node --version

  3. If the version is 17, this might be the reason for the error (as it was in my case)

  4. Run nvm install 14. After installing is complete, it should also switch your node version to 14.

  5. Check the version node --version just in case. If you still see 17, run nvm use 14

Your node --version should now be 14. >Note: Every time you close the current terminal tab, your default node version will return back to 17 unless you change this.

Next time you have to switch node version to 14, you don't have to install it again, just run nvm use 14

Solution 17 - Reactjs

I had the same problem 5 minutes ago, which is strange because it was working, but anyway, in my case the problem was in version 3.0 of the package "resolve-url-loader", after upgrading to version 5.0, everything has been resolved.

npm i resolve-url-loader@^5.0.0 --save-dev

If you have this package and node 17+, try to update it to the latest version, outdated versions cause problems like this.

> If you hit an error in your application with Node.js 17, it’s likely > that your application or a module you’re using is attempting to use an > algorithm or key size which is no longer allowed by default with > OpenSSL 3.0. A command-line option, , has been added to revert to the > legacy provider as a temporary workaround for these tightened > restrictions.ERR_OSSL_EVP_UNSUPPORTED--openssl-legacy-provider > > For details about all the features in OpenSSL 3.0 please see the > OpenSSL 3.0 release blog. > > Contributed in https://github.com/nodejs/node/pull/38512, > https://github.com/nodejs/node/pull/40478

https://nodejs.org/en/blog/release/v17.0.0/#openssl-3-0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJulian ChuView Question on Stackoverflow
Solution 1 - ReactjsAnmol NoorView Answer on Stackoverflow
Solution 2 - ReactjslaugreView Answer on Stackoverflow
Solution 3 - ReactjsStijn BakkerView Answer on Stackoverflow
Solution 4 - ReactjsRob van der LeekView Answer on Stackoverflow
Solution 5 - ReactjskeshgurungView Answer on Stackoverflow
Solution 6 - ReactjsapinanyogaratnamView Answer on Stackoverflow
Solution 7 - ReactjsRahmat OktrifiantoView Answer on Stackoverflow
Solution 8 - ReactjsOliView Answer on Stackoverflow
Solution 9 - ReactjsRazView Answer on Stackoverflow
Solution 10 - ReactjsMahesh MoreView Answer on Stackoverflow
Solution 11 - ReactjsDen SkulimovskiyView Answer on Stackoverflow
Solution 12 - ReactjsOded BDView Answer on Stackoverflow
Solution 13 - ReactjsArif ShaikhView Answer on Stackoverflow
Solution 14 - ReactjsHamletHubView Answer on Stackoverflow
Solution 15 - ReactjsViajanDeeView Answer on Stackoverflow
Solution 16 - ReactjsMichal MoravikView Answer on Stackoverflow
Solution 17 - ReactjsMacedo_MontalvãoView Answer on Stackoverflow