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

新手上路,请多包涵

这是一个 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

原文由 Julian Chu 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 4.3k
2 个回答

我也遇到了同样的问题,因为我安装了最新版本的 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

这对我有用。

原文由 Anmol Noor 发布,翻译遵循 CC BY-SA 4.0 许可协议

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

原文由 laugre 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题