错误:仅具有以下方案的 URL:使用 monorepo 中的 NX 生成的 NestJS 应用程序中的默认 ESM 加载程序支持文件和数据

2024-04-16

我有一个用 NX v16 生成的 Monorepo。我里面有正在运行的 React 应用程序。我使用来自 NX VS Code 插件的 nx 生成器命令生成了 NestJS 应用程序,但是当我启动 Nest 应用程序时nx run <ny-app-name>:serve我收到此错误:Error: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'。我的 React 应用程序没有这个问题,只有 NestJS 才有这个问题。 我使用的是 Windows 11,我的 Node 版本是 18.16.0。这很可能是与 Windows 相关的问题,但我不知道如何克服它,在搜索此类修复程序时我也不了解互联网上的内容。 这是我的 package.json 内容:

{
  "name": "my-nx-monorepo",
  "version": "0.1.0",
  "license": "MIT",
  "scripts": {
    "graph": "npx nx graph",
    "dashboard": "npx nx run dashboard:serve",
    "dashboard:lint": "npx nx run dashboard:lint",
    "dashboard:test": "npx nx run dashboard:test",
    "dashboard:build": "npx nx run dashboard:build",
    "connect-to-nx-cloud": "npx nx connect-to-nx-cloud"
  },
  "private": true,
  "dependencies": {
    "@nestjs/common": "^9.1.1",
    "@nestjs/core": "^9.1.1",
    "@nestjs/platform-express": "^9.1.1",
    "@swc/helpers": "~0.5.0",
    "@tanstack/react-query": "^4.29.5",
    "@tanstack/react-query-devtools": "^4.29.6",
    "@xstate/react": "^3.2.2",
    "axios": "^1.4.0",
    "clsx": "^1.2.1",
    "i18next": "^22.4.15",
    "i18next-browser-languagedetector": "^7.0.1",
    "normalize.css": "^8.0.1",
    "react": "18.2.0",
    "react-aria": "^3.24.0",
    "react-dom": "18.2.0",
    "react-i18next": "^12.2.2",
    "react-router-dom": "^6.11.1",
    "react-stately": "^3.22.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.0",
    "tslib": "^2.3.0",
    "xstate": "^4.37.2"
  },
  "devDependencies": {
    "@babel/preset-react": "^7.14.5",
    "@nestjs/schematics": "^9.1.0",
    "@nestjs/testing": "^9.1.1",
    "@nx/cypress": "16.1.0",
    "@nx/eslint-plugin": "16.1.0",
    "@nx/jest": "16.1.4",
    "@nx/js": "16.1.4",
    "@nx/linter": "16.1.0",
    "@nx/nest": "16.1.4",
    "@nx/node": "16.1.4",
    "@nx/react": "16.1.0",
    "@nx/vite": "16.1.0",
    "@nx/webpack": "16.1.4",
    "@nx/workspace": "16.1.0",
    "@swc/cli": "~0.1.62",
    "@swc/core": "~1.3.51",
    "@tanstack/eslint-plugin-query": "^4.29.4",
    "@testing-library/react": "14.0.0",
    "@total-typescript/ts-reset": "^0.4.2",
    "@types/jest": "^29.4.0",
    "@types/node": "18.14.2",
    "@types/react": "18.0.28",
    "@types/react-dom": "18.0.11",
    "@typescript-eslint/eslint-plugin": "^5.58.0",
    "@typescript-eslint/parser": "^5.58.0",
    "@vitejs/plugin-react": "^3.0.0",
    "@vitest/coverage-c8": "^0.31.0",
    "@vitest/ui": "^0.31.0",
    "cypress": "^12.11.0",
    "eslint": "~8.15.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-plugin-cypress": "^2.10.3",
    "eslint-plugin-import": "2.27.5",
    "eslint-plugin-jsx-a11y": "6.7.1",
    "eslint-plugin-react": "7.32.2",
    "eslint-plugin-react-hooks": "4.6.0",
    "jest": "^29.4.1",
    "jest-environment-node": "^29.4.1",
    "jsdom": "~20.0.3",
    "nx": "16.1.0",
    "nx-cloud": "latest",
    "prettier": "^2.6.2",
    "react-test-renderer": "18.2.0",
    "sass": "^1.55.0",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "typescript": "~5.0.2",
    "vite": "^4.3.4",
    "vite-plugin-eslint": "^1.8.1",
    "vite-tsconfig-paths": "^4.0.2",
    "vitest": "^0.31.0"
  }
}


我刚刚发现这是与 NX v16.1.4 相关的特定错误,NX 团队已解决但尚未发布。他们提供的解决方案(而且足够好)是将您的 monorepo nx 软件包从 v16.1.4 降级到 v16.1.0。这有效,我刚刚测试过,一切正常。他们将在未来的版本中添加修复程序。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:仅具有以下方案的 URL:使用 monorepo 中的 NX 生成的 NestJS 应用程序中的默认 ESM 加载程序支持文件和数据 的相关文章

随机推荐