Search code examples
nestjsnrwl-nxnomachine-nx

Error: Only URLs with a scheme in: file and data are supported by the default ESM loader in NestJS app generated with NX in a monorepo


I have a Monorepo generated with NX v16. I have working React app inside. I generated NestJS app with the nx generator command coming from the NX VS Code plugin, but the moment I start the nest app with nx run <ny-app-name>:serve I receive this error: 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:'. I don't have this issue with my React app, only with the NestJS one. I am on Windows 11, my Node version is 18.16.0. This most likely is Windows related issue but I have no clue how to overcome it, neither I understood something from the internet while searching for such fix. This is my package.json content:

{
  "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"
  }
}


Solution

  • I've just found out that this is a specific bug related to NX v16.1.4 which the NX team has resolved but not released yet. The solution they offer, and it's good enough one is to downgrade your monorepo nx packages from v16.1.4 to v16.1.0. This works, I've just tested it and everything is working correctly. They will add their fix in a future release.