错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:包子路径“./lib/tokenize”未由 node_modules 中模块的 package.json 中的 "exports" 定义

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

这是一个 React 网络应用程序。当我运行

npm start

发生此错误

> 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

只有当我在这台我没有超级用户访问权限的特定计算机上 运行 时才会出现此错误。它适用于其他计算机。

作为参考,这是 ./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
  }
}

这就是我在 ./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

我也遇到了同样的问题,因为我安装了最新版本的 Node.js (v17.0.1)。

只需选择 node.js v14.18.1 并删除最新版本即可使用稳定版本 v14.18.1

nvm uninstall <version>

nvm uninstall v17.0.1

然后安装 LTS 一个 v14.18.1

nvm install --lts

这对我有用。

删除 node_modules 文件夹和 .lock 文件并重新安装您的包(yarn 或 npm)。 它适用于 nodejs 的最后 17.0.1,我可以 npm(或 yarn)再次启动我的应用程序。

回滚到 Node 16.8.0 或(对我有用)稳定版本 16.13.0:

第 1 步:安装 n

npm install -g n

第2步:install/set节点最新稳定版

sudo n stable

或设置16.8.0

sudo n 16.8.0

注意,如果你不能或不想对 n 使用 sudo,你可以 set environment variables 作为位置,例如;

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

删除并重新安装锁和节点模块没有帮助,但 npm update 对我有用

删除 node_modules & package-lock.json 后,我 运行

npm audit fix --force 

& 将 react-scripts 更新为最新可用版本

npm install react-scripts@latest

我刚刚做了:

npm update
npm start

对我有用。

如果你使用纱线,你可以:

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

对于 npm:

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

我遇到了类似的问题,这是由于节点版本 v17.1.0。

我有安装了 3 个不同版本节点的 nvm。刚刚使用 nvm 切换到版本 v14.18.1,问题已解决。

我的工作解决方案是使用纱线:

  • 删除了 /node_modulesyarn.lock 文件。
  • 然后使用 yarn install 重新安装我删除的 packages/file。

成功了!!!

FWIW,我在通过 Homebrew 安装 Node 17.0.1 的 macOS Monterey 上遇到了这个问题。降级到 Node 16.x 对我有用。

使用 Homebrew 从节点 17.x(最新)降级到节点 16.x:

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

我在使用 Node.js v17.0.1(最新功能)时也遇到错误 - 我正在使用 macOS Catalina 和自制软件。

所以我想将 Node.js v17.0.1 切换到 Node.js (LTS) -> Node.js v16.3.1

我使用以下命令使用自制程序卸载节点:

brew uninstall node

然后我从 https://nodejs.org/en/ 下载 Node LTS 并安装它。

这是我的工作。谢谢:)

删除 node_module & 包-lock.json

然后

npm install 

( 在安装中,如果您在使用 --force--legacy-peer-deps 命令时遇到错误,如

`npm install --legacy-peer-deps`

)

npm start

最新版“react-scripts”的更新对我有用!之前的“react-scripts”版本是 4.0.3,我已经更新到 5.0.0。节点版本为 17.0.1.

我正在接收 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:程序包子路径 './lib/parser' 未由 ...node_modules\next\node_modules\postcss\package.json

中的“exports”定义

升级react后在node版本17.4.0上解决,nextjs使用:

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

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

卸载当前 Node.js 并安装 LTS 可以解决问题,但如果您想保留当前安装的版本,可以使用 nvs add lts 安装最新的 Node.js LTS,并使用 nvs use node/<lts version>/<platform> 激活它。 LTS 版本和平台值将在第一个命令输出中提供。

我不明白为什么@AnmolNoor 要你卸载版本 17。

正确的做法:

  1. 确保您有 nvm (https://github.com/nvm-sh/nvm)。如果您不这样做,我强烈建议您安装它。

  2. 检查你的node --version

  3. 如果版本是 17,这可能是错误的原因(就像我的情况一样)

  4. 运行nvm install 14。安装完成后,它也应该将你的节点版本切换到 14.

  5. 检查版本node --version以防万一。如果您仍然看到 17,运行 nvm use 14

您的 node --version 现在应该是 14。

Note: Every time you close the current terminal tab, your default node version will return back to 17 unless you change this.

下次要切换node版本到14的时候,不用再安装了,直接运行 nvm use 14

我在 5 分钟前遇到了同样的问题,这很奇怪,因为它正在工作,但无论如何,在我的情况下,问题出在软件包“resolve-url-loader”的 3.0 版中,在升级到 5.0 版之后,一切都解决了。

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

如果你有这个包和node 17+,请尝试更新到最新版本,过时的版本会导致这样的问题。

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