nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.65k stars 2.36k forks source link

Error serving standalone app (fastify, express) #16831

Closed lucas-labs closed 1 year ago

lucas-labs commented 1 year ago

Current Behavior

> nx run repro:serve:development

[ watch ] build succeeded, watching for changes...
Debugger listening on ws://localhost:9229/f630444b-c355-463a-85f8-dded6237a6e5
Debugger listening on ws://localhost:9229/f630444b-c355-463a-85f8-dded6237a6e5
For help, see: https://nodejs.org/en/docs/inspector
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 'd:'
    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)

Expected Behavior

It should serve the app

GitHub Repo

https://github.com/lucas-labs/nx-issue-repro

Steps to Reproduce

  1. Create the workspace selecting node-standalone - fastify

    
    $ npx create-nx-workspace@latest
    
    >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

√ Choose what to create · node-standalone √ Application name · repro √ What framework should be used? · fastify √ Would you like to generate a Dockerfile? [https://docs.docker.com/] · No √ Enable distributed caching to make your CI faster · No

2.  Serve the app: `npm run start` (`nx run repro:serve:development`)

### Nx Report

```shell
Node   : 20.1.0
   OS     : win32 x64
   npm    : 9.6.4
   Hasher : Native

   nx (global)        : 16.1.1
   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/devkit         : 16.1.1
   @nx/esbuild        : 16.1.1
   @nx/eslint-plugin  : 16.1.1
   @nx/node           : 16.1.1
   @nrwl/tao          : 16.1.1
   typescript         : 5.0.4

Failure Logs

> nx run repro:serve:development

[ watch ] build succeeded, watching for changes...
Debugger listening on ws://localhost:9229/d12b87a6-7ed6-4627-a235-b2d0e217f819
Debugger listening on ws://localhost:9229/d12b87a6-7ed6-4627-a235-b2d0e217f819
For help, see: https://nodejs.org/en/docs/inspector
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 'd:'
    at new NodeError (node:internal/errors:399:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:972:11)
    at defaultResolve (node:internal/modules/esm/resolve:1051:3)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:307:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:156:32)
    at DefaultModuleLoader.import (node:internal/modules/esm/loader:266:12)
    at importModuleDynamically (node:internal/modules/cjs/loader:1197:37)
    at importModuleDynamicallyWrapper (node:internal/vm/module:428:21)
    at importModuleDynamically (node:internal/vm:105:46)
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:87:14)

Operating System

Additional Information

Searching old issues I found that a similar error happened with Node < v14. Tried with node versions: 20.1.0, 20.0.0, 18.16.0 and 16.14.0 and got the same error message.

ZenSoftware commented 1 year ago

I am getting the same error while trying to serve my Nest app after upgrading Nx from v16.1.0 to v16.1.1. I have tried this on both Node v18 and Node v20 and the issue occurs on both. Reverting to v16.1.0 resolves the issue.

Nx Report

   Node   : 20.1.0
   OS     : win32 x64
   pnpm   : 8.3.1
   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
   @nx/storybook      : 16.1.1
   @nrwl/tao          : 16.1.1
   @nx/webpack        : 16.1.1
   typescript         : 5.0.4
   ---------------------------------------
   Community plugins:
   @storybook/angular : 7.0.9
   apollo-angular     : 4.2.1

Operating System

B1Z1 commented 1 year ago

Same problem on windows 11

WarrenMfg commented 1 year ago

Same for macOS


> nx run express:serve:development

 >  NX   Cannot find module 'ajv/dist/compile/codegen'

   Require stack:
   - /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/definitions/typeof.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/keywords/typeof.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/keywords/index.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/index.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/schema-utils/dist/validate.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/schema-utils/dist/index.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/copy-webpack-plugin/dist/index.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/utils/create-copy-plugin.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/utils/with-nx.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/executors/webpack/lib/get-webpack-config.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/executors/webpack/webpack.impl.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/nx/src/config/workspaces.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/nx/src/command-line/run.js
   - /Users/kennethwarren/Desktop/wmfg/node_modules/nx/bin/run-executor.js

Error: Cannot find module 'ajv/dist/compile/codegen'
Require stack:
- /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/definitions/typeof.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/keywords/typeof.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/keywords/index.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/index.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/schema-utils/dist/validate.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/schema-utils/dist/index.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/copy-webpack-plugin/dist/index.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/utils/create-copy-plugin.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/utils/with-nx.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/executors/webpack/lib/get-webpack-config.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/@nx/webpack/src/executors/webpack/webpack.impl.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/nx/src/config/workspaces.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/nx/src/command-line/run.js
- /Users/kennethwarren/Desktop/wmfg/node_modules/nx/bin/run-executor.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/kennethwarren/Desktop/wmfg/node_modules/ajv-keywords/dist/definitions/typeof.js:3:19)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)

 >  NX   Running target serve for project express failed
huulai commented 1 year ago

@lucas-labs I have the same issue. I tried downgrading all versions to 16.0.3 and it worked. https://github.com/nrwl/nx/issues/16834#issuecomment-1537154263

Duccem commented 1 year ago

I have the same problem serving nestjs app 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)

##Nx Report
 Node   : 18.16.0

OS : win32 x64 npm : 9.5.1 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/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/webpack : 16.1.1 nx-cloud : 16.0.5 typescript : 5.0.4

AgentEnder commented 1 year ago

I'm closing this as a duplicate of #16834

lucas-labs commented 1 year ago

Same for macOS

Seems like a different problem, you probably need to npm install

github-actions[bot] commented 1 year ago

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.