create-react-app: Builds Don't Work with PostCSS After Update

In Node v17:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /tmp/workspace/node_modules/postcss-safe-parser/node_modules/postcss/package.json

In earlier versions of Node, this was just a deprecation warning:

Update this package.json to use a subpath pattern like "./*".

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 56
  • Comments: 44

Commits related to this issue

Most upvoted comments

@timashov, rolling back to Node 16.8.0 helped me.

on node v17.0.1. deleted yarn.lock and node_modules then did yarn install and worked for me

High chance it will break the application, i recommend you never do that to your project

Nuked my node modules and yarn.lock and ran yarn install and it worked. Using cra typescript template.

Just remove yarn.lock & node_modules & run yarn

Why is this closed? I don’t see a fix… Only some pretty risky workarounds

Can we get a real fix and not downgrading Node version? Current LTS is now 18.13.0.

Package subpath ‘./lib/parser’ is not defined by “exports” in /home/node/app/node_modules/postcss/package.json I am getting an error like this today suddenly.

Having this issue, wiping out node_modules didn’t work, the only solution that’s worked for me is nvm use 16.8.0.

why is this closed ? what’s the real fix ?

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)

npm audit fix --force also fixed this issue for me

@Senbonzakura1234 The application is already broken. I don’t understand why one would hesitate to do this on a fresh cra app ??

npm audit fix --force fixed this issue for me

I used these commands to deploy to production on Vercel. Simply insert it in the “Install Command” field. Rename your yarn.lock or package.lock files ending with -backup from github repo just incase of anything.

npm install next@12 && npm install react@latest react-dom@latest && npm i --package-lock-only && yarn install && npm audit fix --force

Upgrading should solve your issue: https://nextjs.org/docs/upgrading

npm i next@latest react@latest react-dom@latest eslint-config-next@latest
# or
yarn add next@latest react@latest react-dom@latest eslint-config-next@latest
# or
pnpm up next react react-dom eslint-config-next --latest

I sort it by using nvm install --lts

on node v17.0.1. deleted yarn.lock and node_modules then did yarn install and worked for me

npm audit fix --force

this works for me

Ok so I actually got pass this issue but updating to postcss": “8.2.12”

My node was 17.0. Had to get LTS nvm install lts

If you don’t have nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash source ~/.nvm/nvm.sh

yarn upgrade worked for me.

or you can use nvm with engines field in package.json

I think the easy fix for this would be to go back a node version, so let’s say if you’re on 17.7, you want to go to 16.6 or anything lower than 17…

This problem occurred for me and I used Volta which helped me go back a node version really easily… After you’re done installing Volta, you can do this and enjoy your React App 😄

volta install node
cd your-app
volta pin node

Package subpath ‘./lib/parser’ is not defined by “exports” in /home/node/app/node_modules/postcss/package.json I am getting an error like this today suddenly.

i also got this issue either

Were you able to find resolution?

I did the same as people above, migrate back to node 16.8.0

The solution of removing yarn.lock and node_modules does not work for me. I get a large number of these errors, and Yarn fails:

➤ YN0001: │ Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (node:internal/errors:371:5)
    at PassThrough.onclose (node:internal/streams/end-of-stream:122:30)
    at PassThrough.emit (node:events:390:28)
    at emitCloseNT (node:internal/streams/destroy:145:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

This is related to postcss/postcss-safe-parser#29. Which is actually entirely CRA’s fault because react-scripts@4.0.3 is using PostCSS 7 (obsolete) and an old version of postcss-safe-parser.

It looks like the work fixing this issue was already merged in July (PostCSS was updated to version without this Node 17 issue in #11121, and postcss-safe-parser was removed in #11201). However none of that has been released yet. All of that is being pushed to CRA v5, however I don’t see anything in the 5.0 milestone that should in any way block a CRA 5.0 release.