0

我正在使用Nuxt 3Express 4创建一个网站,并尝试通过git在 Gandi Simple Hosting实例上部署它。虽然它在本地运行良好(Node.js 16.13.0),但在部署时(Node.js 17.4)我有这个由unenv包导入引起的错误:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './runtime/polyfill/fetch.node' is not defined by "exports" in /srv/data/web/vhosts/default/client/.output/server/node_modules/unenv/package.json imported from /srv/data/web/vhosts/default/client/.output/server/index.mjs
    at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:496:3)
    at packageResolve (internal/modules/esm/resolve.js:618:14)
    at moduleResolve (internal/modules/esm/resolve.js:670:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:784:11)
    at Loader.resolve (internal/modules/esm/loader.js:85:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:51:40)
    at link (internal/modules/esm/module_job.js:50:36) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

我不是唯一一个有这个错误的人,正如在这个开放问题中看到的那样,关于在 Firebase 上的部署:https ://github.com/nuxt/framework/issues/2151 。

随 Nuxt 3 nitro 服务器分发的unnev package.json 是:

{
  "name": "unenv",
  "version": "0.4.3",
  "description": "",
  "repository": "unjs/unenv",
  "license": "MIT",
  "exports": {
    ".": {
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs"
    },
    "./runtime/*": {
      "require": "./runtime/*.cjs",
      "import": "./runtime/*.mjs"
    }
  },
  "main": "./dist/index.cjs",
  "types": "./dist/index.d.ts",
  "files": [
    "dist",
    "runtime"
  ],
  "scripts": {
    "build": "unbuild",
    "lint": "eslint --ext ts .",
    "prepack": "unbuild",
    "release": "standard-version && npm publish && git push --follow-tags"
  },
  "dependencies": {
    "buffer": "^6.0.2",
    "defu": "^5.0.0",
    "events": "^3.2.0",
    "inherits": "^2.0.4",
    "mime": "^2.4.6",
    "node-fetch": "^3.0.0",
    "process": "^0.11.10",
    "upath": "^2.0.1",
    "util": "^0.12.4"
  },
  "devDependencies": {
    "@nuxtjs/eslint-config-typescript": "latest",
    "@types/node": "latest",
    "@types/node-fetch": "latest",
    "consola": "latest",
    "eslint": "latest",
    "standard-version": "latest",
    "typescript": "latest",
    "unbuild": "latest"
  }
}

这个非 Nuxt 问题(Storybook.js)表明在 Node 17 之前只抛出了一个警告。

即使我可以考虑降级我的 Node.js 版本,我也想知道这个错误是否可以在 Node.js 17 上修复,如果不能,如何"exports"重构该条目以使其工作。

4

0 回答 0