Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only URLs with a scheme in: file and data are supported by the default ESM loader. #16834

Closed
1 of 4 tasks
WCN-llc opened this issue May 6, 2023 · 18 comments · Fixed by #16911
Closed
1 of 4 tasks

Only URLs with a scheme in: file and data are supported by the default ESM loader. #16834

WCN-llc opened this issue May 6, 2023 · 18 comments · Fixed by #16911
Labels
os: windows Issues that can only be replicated on Windows outdated scope: node Issues related to Node, Express, NestJS support for Nx type: bug

Comments

@WCN-llc
Copy link

WCN-llc commented May 6, 2023

Current Behavior

Project won't start NestJS

Expected Behavior

Project launches NestJS

GitHub Repo

No response

Steps to Reproduce

1.Create a NestJS project and run

Nx Report

nx report

 >  NX   Report complete - copy this into the issue template

   Node   : 18.16.0
   OS     : win32 x64
   yarn   : 1.22.19
   Hasher : Native

   nx                 : 16.1.1
   @nx/js             : 16.1.1
   @nx/jest           : 16.1.1
   @nx/linter         : 16.1.1
   @nx/workspace      : 16.1.1
   @nx/angular        : 16.1.1
   @nx/cypress        : 16.1.1
   @nx/devkit         : 16.1.1
   @nx/eslint-plugin  : 16.1.1
   @nx/nest           : 16.1.1
   @nx/node           : 16.1.1
   @nrwl/tao          : 16.1.1
   @nx/web            : 16.1.1
   @nx/webpack        : 16.1.1
   typescript         : 5.0.4

Failure Logs

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:'
    at new NodeError (node:internal/errors:399:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
    at defaultResolve (node:internal/modules/esm/resolve:1135:3)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:525:22)
    at importModuleDynamically (node:internal/modules/cjs/loader:1186:29)
    at importModuleDynamicallyWrapper (node:internal/vm/module:429:21)
    at importModuleDynamically (node:internal/vm:106:46)

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

It may not be your fault.
So, I apologize if it is.

@huulai
Copy link

huulai commented May 6, 2023

@WCN-llc

I tried downgrading all versions to 16.0.3 and it worked. You can try while waiting for them to fix the latest version.

nx report

Node   : 20.1.0
OS     : win32 x64
npm    : 9.6.4
Hasher : Native
nx (global)        : 16.1.1
nx                 : 16.0.3
@nx/js             : 16.0.3
@nx/jest           : 16.0.3
@nx/linter         : 16.0.3
@nx/workspace      : 16.0.3
@nx/cypress        : 16.0.3
@nx/devkit         : 16.0.3
@nx/eslint-plugin  : 16.0.3
@nx/nest           : 16.0.3
@nx/next           : 16.0.3
@nx/node           : 16.0.3
@nx/react          : 16.0.3
@nrwl/tao          : 16.0.3
@nx/web            : 16.0.3
@nx/webpack        : 16.0.3
typescript         : 5.0.4

@AgentEnder AgentEnder added the scope: node Issues related to Node, Express, NestJS support for Nx label May 8, 2023
@AgentEnder AgentEnder added the os: windows Issues that can only be replicated on Windows label May 8, 2023
@ndcunningham
Copy link
Contributor

ndcunningham commented May 8, 2023

Hi, thanks for reporting,

I tried this on my Windows machine with a fresh WSL install.
Can you tell me what version of node you are using? node -v

When I did not have node installed on my WSL distro I got the same error. (I had node installed on the Windows side but not the distro).

After I installed node the current lts version 18.16.0 it worked as expected.

@jspivack
Copy link

jspivack commented May 8, 2023

I'm getting this in Windows with node 18.16.0 installed, outside of a WSL environment

@AdditionAddict

This comment was marked as duplicate.

@jvinis
Copy link

jvinis commented May 9, 2023

I got the same error with node LTS 18.16.0
I created an Angular project, NestJs project with NX Console @nx/angular and @nx/nest
The angular served, but the nest throws

"Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'"

@fercik
Copy link

fercik commented May 9, 2023

I have the same issue:

Node   : 18.13.0
OS     : win32 x64
npm    : 9.6.6
Hasher : Native

nx                 : 16.1.3
@nx/js             : 16.1.3
@nx/jest           : 16.1.3
@nx/linter         : 16.1.3
@nx/workspace      : 16.1.3
@nx/angular        : 16.1.3
@nx/cypress        : 16.1.3
@nx/devkit         : 16.1.3
@nx/eslint-plugin  : 16.1.3
@nx/nest           : 16.1.3
@nx/node           : 16.1.3
@nrwl/tao          : 16.1.3
@nx/webpack        : 16.1.3
typescript         : 5.0.4

I can also confirm that reverting to 16.1.0 solves the issue.

@flut1
Copy link

flut1 commented May 9, 2023

I think I've narrowed it down to #10414

Reverting the change in packages/js/src/executors/node/node-with-require-overrides.ts back to a require() call seems to resolve the issue. The NX_FILE_TO_RUN environment variable is an absolute windows path (starting with C:\ for example) and node doesn't seem to like that when using dynamic import.

This goes a bit beyond my understanding of how NX works to implement a fix but hopefully this will help someone else to create a patch

@MarkKla
Copy link

MarkKla commented May 10, 2023

I am having the same issue. How can I fix this?

@fercik
Copy link

fercik commented May 10, 2023

@MarkKla

I am having the same issue. How can I fix this?

For now, reverting to 16.1.0 seems like a good option until there is an official fix.

@jaysoo
Copy link
Member

jaysoo commented May 10, 2023

We'll release a patch for this. Thanks for reporting!

@reactoholic
Copy link

reactoholic commented May 12, 2023

My nx version in my package.json file is 16.1.0 and I still hit issue. What else must be downgrade in my packages so I can serve successfully a NodeJS app?
Here 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"
  }
}

@wizardnet972
Copy link
Contributor

wizardnet972 commented May 12, 2023

@KibobiShtrudelz, you have the 16.1.4 version in your package.json:

"@nx/nest": "16.1.4",
    "@nx/node": "16.1.4",

When you add a js lib, nx will update your package json to 16.1.4. so beware of this behavior.

@reactoholic
Copy link

@KibobiShtrudelz, you have the 16.1.4 version in your package.json:

"@nx/nest": "16.1.4",
    "@nx/node": "16.1.4",

Thank you for your lightning fast answer!
I am literally doing this right now but and since you're confirming me this I feel better and I hope It will work ^_^

@reactoholic
Copy link

@wizardnet972 Sorry to bother you, one last question. I just downgraded - which option from the nx generator dropdown menu should I choose for NestJS app: @nx/nest or @nestjs/schematics? What's the difference between the two?

@wizardnet972
Copy link
Contributor

@KibobiShtrudelz In this case, I would recommend choosing @nx/nest from the nx generator dropdown menu. The reason behind this is that Nx has its own collection of schematics specifically designed to work within an Nx workspace and align with its mindset. On the other hand, @nestjs/schematics originates from the nest package and is intended for use in "regular" NestJS projects. By selecting @nx/nest, you can take advantage of the tailored schematics and optimizations provided by Nx for a NestJS application within an Nx workspace.

@IbnAdamnet
Copy link

/node-with-require-overrides.ts

Please where is this file Sir?

@IbnAdamnet
Copy link

I think I've narrowed it down to #10414

Reverting the change in packages/js/src/executors/node/node-with-require-overrides.ts back to a require() call seems to resolve the issue. The NX_FILE_TO_RUN environment variable is an absolute windows path (starting with C:\ for example) and node doesn't seem to like that when using dynamic import.

This goes a bit beyond my understanding of how NX works to implement a fix but hopefully this will help someone else to create a patch

Please do help explain exactly how, This.Is.Frustrating

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
os: windows Issues that can only be replicated on Windows outdated scope: node Issues related to Node, Express, NestJS support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.