1

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

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in C:\Users\Masum PC\ami-parbona\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. (C:\Users\Masum PC\ami-parbona\node_modules\postcss-safe-parser\lib\safe-parser.js:1:17) { code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' }

Node.js v17.0.1

Masum Ali
  • 19
  • 1
  • 1
  • 4
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 04 '21 at 03:48
  • 2
    Try [this answer](https://stackoverflow.com/a/69706112/16223122) in [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](https://stackoverflow.com/questions/69693907/error-err-package-path-not-exported-package-subpath-lib-tokenize-is-not-d) Also see the "workaround" in the comment – Pablo LION Dec 14 '21 at 22:40

6 Answers6

4

I totally agree with TripleM's answer (please refer to that answer for more details) but I'm going to suggest a short and sweet answer here.

First, uninstall these 3 npm packages: (next, react, react-dom)

npm uninstall next react react-dom

Then, reinstall them with the latest versions

npm install --save next react react-dom

If this method is not working for you try TripleM's answer, that might work for you.

Kesara Wimal
  • 639
  • 13
  • 22
3

While doing on my nextJs project -

npm run dev

I found the same error. I have solved this by doing some steps.

  1. Created a new project on other folder using npx create-next-app@latest (or for react project use the respective command to create a new project)
  2. In My current project where I'm getting the error I deleted the node_modules folder and package-lock.json file (not the package.json file)
  3. Opened the package.json file of current project and replaced the next ,react, react-dom version with latest project's version which I have created on other folder.
  4. Now simply npm install and then run the project

Explanation:- This error normally occur if you trying to run a old project where versions are different than your current installed version. So you need to use exact version on package.json file as current installed version. If you exactly know the versions then no need to create a new project , just replace the version.

While searching for the solution over stackoverflow I found that npm update command worked well for others because that answer was upvoted. But for me (using ubuntu 20) this wasn't working so I need to manually update the version of package.json.

This screenshot

You can see the screenshot which refer the where to replace the new version.

You might have other packages inside the dependencies , you might need to upgrade the latest version of other packages as well.

In my react-native project, I have to upgrade the react-native-camera version to run the application on my new system but it was running well on my old system.

So the conclusion is **UPGRADE THE VERSION(S)**.

TripleM
  • 1,096
  • 7
  • 20
1

This happened to me when I git clone'd this repo.

What worked was downgrading my node.js version from current to lts. I used nvm use --lts.

0

Posting here as I had a different cause.

For me, I was using AWS Amplify, which uses AWS CodeBuild behind the scenes.

I had modified some of my dependencies, devDependencies, and peerDependencies for multiple packages in a monorepo.

The build failed because my web app was trying to pull in an old version of the entities library, way down in the dependency tree.

$ pnpm why entities
html-react-parser 3.0.9
└─┬ html-dom-parser 3.1.3
  └─┬ htmlparser2 8.0.1
    ├─┬ domutils 3.0.1
    │ └─┬ dom-serializer 2.0.0
    │   └── entities 2.2.0
    └── entities 2.2.0

Resulting in this CI/CD build error:

2023-02-22T05:39:28.319Z [INFO]: @myapp/webapp:build: cache miss, executing cd449f2fbd550ffc
2023-02-22T05:39:28.775Z [INFO]: @myapp/webapp:build:
                                 @myapp/webapp:build: > @myapp/webapp@0.1.0 build /codebuild/output/src711556549/src/myapp/apps/webapp
                                 @myapp/webapp:build: > react-scripts build
                                 @myapp/webapp:build:
2023-02-22T05:39:28.952Z [INFO]: @myapp/webapp:build: node:internal/modules/cjs/loader:560
                                 @myapp/webapp:build:       throw e;
                                 @myapp/webapp:build:       ^
                                 @myapp/webapp:build:
                                 @myapp/webapp:build: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/decode_codepoint' is not defined by "exports" in /codebuild/output/src711556549/src/myapp/node_modules/.pnpm/node_modules/entities/package.json
                                 @myapp/webapp:build:     at new NodeError (node:internal/errors:387:5)
                                 @myapp/webapp:build:     at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
                                 @myapp/webapp:build:     at packageExportsResolve (node:internal/modules/esm/resolve:649:3)
2023-02-22T05:39:28.953Z [INFO]: @myapp/webapp:build:     at resolveExports (node:internal/modules/cjs/loader:554:36)
                                 @myapp/webapp:build:     at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)
                                 @myapp/webapp:build:     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1007:27)
                                 @myapp/webapp:build:     at Function.Module._load (node:internal/modules/cjs/loader:866:27)
                                 @myapp/webapp:build:     at Module.require (node:internal/modules/cjs/loader:1093:19)
                                 @myapp/webapp:build:     at require (node:internal/modules/cjs/helpers:108:18)
                                 @myapp/webapp:build:     at Object.<anonymous> (/codebuild/output/src711556549/src/myapp/node_modules/.pnpm/node_modules/htmlparser2/lib/Tokenizer.js:6:42) {
                                 @myapp/webapp:build:   code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
                                 @myapp/webapp:build: }
2023-02-22T05:39:28.957Z [INFO]: @myapp/webapp:build:  ELIFECYCLE  Command failed with exit code 1.
2023-02-22T05:39:28.962Z [WARNING]: @myapp/webapp:build: ERROR: command finished with error: command (/codebuild/output/src711556549/src/myapp/apps/webapp) pnpm run build exited (1)
2023-02-22T05:39:28.962Z [WARNING]: command (/codebuild/output/src711556549/src/myapp/apps/webapp) pnpm run build exited (1)
                                    ERROR  run failed: command  exited (1)

It took me a while to realize that, in my build settings, the build was caching node_modules:

      cache:
        paths:
          - node_modules/**/*

The solution, I just needed to comment the about build settings line, kick off another build, then un-comment.

      cache:
        paths:
          # - node_modules/**/*

After the build succeeded, I restored this caching of the node_modules so that future CI/CD builds would be potentially faster.

The correct dependency tree:

$ pnpm why entities 
html-react-parser 3.0.9
└─┬ html-dom-parser 3.1.3
  └─┬ htmlparser2 8.0.1
    ├─┬ domutils 3.0.1
    │ └─┬ dom-serializer 2.0.0
    │   └── entities 4.4.0
    └── entities 4.4.0

See build setting info here: https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html#yml-specification-syntax

Chris Livdahl
  • 4,662
  • 2
  • 38
  • 33
0

add --openssl-legacy-provider to the package.json where scripts It should turn out like this

"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 07 '23 at 13:44
0

I also had the same problem and as mentioned above the solution is to execute inside the same project, where you run the install command:

npm install
npm update
Georgi Stoyanov
  • 594
  • 1
  • 9
  • 26