159

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 <andrey@sitnik.ru>",
  "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
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Julian Chu
  • 1,790
  • 2
  • 7
  • 12

25 Answers25

148

I'm also stuck with the same problem because I installed the latest version of Node.js.


For Linux users who use NVM to manage node

nvm uninstall <version>

now install the LTS version

nvm install --lts

This worked for me.


OR


Try to delete Node_modules and the lock file

  1. Delete your node_modules folder, package-lock.json or yarn.lock

  2. Re-Install all the dependencies.

    npm i
    

    or

    yarn
    

For a better understanding of how to install node, check out this blog by digital ocean https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04

Anmol Noor
  • 1,685
  • 1
  • 7
  • 8
  • 6
    you dont need to uninstall the node version btw if you dont want to. you can use an nvmrc file in the project folder, or set a different version as the nvm default – eltonkamami Nov 07 '21 at 18:01
  • so this problem is of installing new version of npm?!! i had this problem too :( – fatemeh kazemi Nov 21 '21 at 10:23
  • 1
    @fatemehkazemi yes it is due to maybe some bug or maybe some old version of settings that exist in our project ... – Anmol Noor Nov 21 '21 at 12:18
  • today i had the exact same problem, installing the lts version solved the issue. before i've done an install of the current node version and upgraded the npm. but this is only my observation not a root cause analysis. – Thomas Poth Dec 05 '21 at 11:07
  • 2
    Thanks! This worked. Couldn't have thought this would be the problem. Cheers – Abhik Banerjee Feb 18 '22 at 12:47
  • 3
    This is not a viable solution because downgrading Node.js is not a good practice. – Greg Tomasik Oct 29 '22 at 19:21
  • 2
    @GregTomasik It might not be a viable solution, but I don't know enough NodeJS to fix thirdparties that are broken. Thus, it's the only viable solution for the majority of the world. – Theodore R. Smith Mar 09 '23 at 08:19
58

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.

laugre
  • 621
  • 4
  • 2
  • 7
    That worked for me but then I got a `Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:67:19)` and that was that :/. – Christopher Oct 26 '21 at 22:17
  • 3
    workaround there -> https://stackoverflow.com/questions/69692842/error0308010cdigital-envelope-routinesunsupported – laugre Oct 28 '21 at 13:08
  • worked for me too – Gunesh Shanbhag Dec 10 '21 at 20:36
  • 1
    @GuneshShanbhag IMHO, to second a comment, it's better to hit the +1 button than post a new comment. – Pablo LION Dec 14 '21 at 22:41
  • Ugh. Not for me - `graphql-request` doesn't like it (specifically the message reads `error graphql-request@3.2.0: The engine "node" is incompatible with this module. Expected version "10.x || 12.x || 14.x". Got "17.0.1"`). – BogeyMan Dec 17 '21 at 02:23
  • 1
    @BogeyMan another issue that could lead to creating a new thread... Maybe you should upgrade your graphql-request version to the last one, check before which version is compatible with Nodejs 17.0.1. But be careful with your project other peer dependencies. – laugre Dec 20 '21 at 10:46
  • I needed to delete package-lock.json and run ```ncu -u``` to upgrade my packages in package.json and then it worked when I installed from there – howard Oct 01 '22 at 22:36
31

my working solution was with yarn:

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

it worked !!!

Abilogos
  • 4,777
  • 2
  • 19
  • 39
keshgurung
  • 327
  • 2
  • 4
21

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
Rob van der Leek
  • 1,486
  • 15
  • 13
19

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
Stijn Bakker
  • 207
  • 1
  • 2
19

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

apinanyogaratnam
  • 628
  • 7
  • 14
  • 1
    Literally this is it... Despite the "more specific" answer re macOS Monterey from Rob van der Leek below; I'm on Monterey running node `v17.0.1` from Homebrew and this was the fix! Thanks! – lol Nov 27 '21 at 01:06
  • This worked for me too, I'm on Catalina running node v17.3.0. Thanks! – Alex Jan 22 '22 at 09:29
  • Looks like this doesn't always work on macOS Monterey running node v17.0.1. I tried it and I get the same error as before. – Patrick Jun 13 '22 at 03:57
7

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
Oli
  • 369
  • 4
  • 8
7

You don't need to roll back to older node versions.

On node.js v18 I solved it by removing the node_modules folder and the package-lock.json file:

rm -rf node_modules package-lock.json

...then running:

npm i
npm audit fix

My next npm start worked just fine.

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
7

This problem can be occur when you are trying to work with an old react repository which is developed with a lower node.js version than v17.0.1 and you are currently using v17.0.1 or a higher node version.

  1. Delete your node_modules folder, package-lock.json and yarn file (if you have one).

  2. Force clean the entire NPM cache by using following command. While executing this command, you might get a warning, just ignore it.

    npm cache clean --force    //WARN using --force Recommended protections disabled.
    
  3. Re-Install all the dependencies.

    npm install
    
Aravinda Meewalaarachchi
  • 2,551
  • 1
  • 27
  • 24
6

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 :)

6

I had this issue with craco and postcss. What I did to solve is

npm i -D postcss@latest
export NODE_OPTIONS=--openssl-legacy-provider
npm install
GregLimo
  • 107
  • 1
  • 2
5

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)

HamletHub
  • 481
  • 1
  • 9
  • 19
3

I just did:

npm update
npm start

worked for me.

Skatox
  • 4,237
  • 12
  • 42
  • 47
Raz
  • 67
  • 1
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 15 '21 at 02:33
3

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

Michal Moravik
  • 1,213
  • 1
  • 12
  • 23
2

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.

1

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
Mahesh More
  • 151
  • 7
1

i removed /node_modules folder,package-lock.json & yarn.lock file, then executed

npm i, then npm audit fix --force

it worked completely fine

1

I was facing the similar problem with namespace.js and have solved my problem by adding the following lines

"./lib/util/namespace":"./lib/util/namespace.js"

in exports of /usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/package.json

Final exports will look like

"exports": {
".": "./lib/environment.js",
"./cli/": "./cli/",
"./lib/": "./lib/",
"./lib/util/": "./lib/util/",
"./adapter": "./lib/adapter.js",
"./conflicter": "./lib/util/conflicter.js",
"./log": "./lib/util/log.js",
"./transform": "./lib/util/transform.js",
"./lib/util/namespace":"./lib/util/namespace.js",
"./package.json": "./package.json"
}
Nitin Jha
  • 1,485
  • 2
  • 10
  • 14
0

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
Oded BD
  • 2,788
  • 27
  • 30
0

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.

Arif Shaikh
  • 79
  • 3
  • 10
0

In my case, this issue occurred due to a version dependencies mismatch. You can simply upgrade your react and next version and try to install npm again by following this command:

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

I updated my next and react versions using this command with a specific version as per my requirement like this,

npm install next@12 react@18 react-dom@18 --force

which worked for me. I hope you find it useful.

Harsh Prajapati
  • 510
  • 5
  • 7
0

This will most likely not help the question author, since his problem is platform specific, but it's another potential cause of this error, which might help others debugging.

Make sure you are importing dependencies from correct place. I ran into:

Error: Package subpath './dist/esm' is not defined by "exports" in /node_modules/kysely/package.json

The reason being:

import { Kysely } from 'kysely/dist/esm'

Instead of:

import { Kysely } from 'kysely'
pakut2
  • 500
  • 5
  • 21
-1

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.

ViajanDee
  • 654
  • 4
  • 15
-1

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

-1

For me, I updated the Node version to the v16.17.1 and removed and reinstall packege.json, now it is fixed