11ty / eleventy-dev-server

A minimal generic web-development web server.
100 stars 14 forks source link

Cannot locate Morphdom module in NPM Workspaces #77

Open ala-n opened 1 month ago

ala-n commented 1 month ago

Steps to Reproduce

The following project structure (with NPM workspaces):

The server runs in the context of the root/11ty-package subpackage.

The domDiff is enabled (default).

Any HTML-related changes lead to an exception during the watch process, with the following error:

[11ty] Unhandled rejection in promise: (more in DEBUG output)
[11ty] The "path" argument must be of type string or an instance of Buffer or URL. Received undefined (via TypeError)
[11ty]
[11ty] Original error stack trace: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
[11ty]     at Object.readFileSync (node:fs:451:42)
[11ty]     at EleventyDevServer._getFileContents (L:\DMT\smart-wc-library\node_modules\@11ty\eleventy\node_modules\@11ty\eleventy-dev-server\server.js:322:23)
[11ty]     at EleventyDevServer.eleventyDevServerMiddleware (L:\DMT\smart-wc-library\node_modules\@11ty\eleventy\node_modules\@11ty\eleventy-dev-server\server.js:426:29)
[11ty]     at EleventyDevServer.onRequestHandler (L:\DMT\smart-wc-library\node_modules\@11ty\eleventy\node_modules\@11ty\eleventy-dev-server\server.js:548:11)
[11ty]     at Server.emit (node:events:518:28)
[11ty]     at parserOnIncoming (node:_http_server:1143:12)
[11ty]     at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)

Root Cause Details:

The EleventyDevServer._getFileContents method tries to read the file content of the morphdom module (ref), but it cannot resolve the path to the file. It uses the following path as a base ./node_modules/morphdom/dist/morphdom-esm.js to create the following searchLocations:

[
  'root/11ty-package/node_modules/morphdom/dist/morphdom-esm.js',
  'root/node_modules/@11ty/eleventy/node_modules/@11ty/eleventy-dev-server/node_modules/morphdom/dist/morphdom-esm.js',
  'root/node_modules/@11ty/eleventy/node_modules/morphdom/dist/morphdom-esm.js'
]

None of them contain morphdom, which is under root/node_modules/morphdom/** in the current state of things.

zachleat commented 1 month ago

Marginally related to https://github.com/11ty/eleventy/issues/3178

zachleat commented 1 month ago

Can you include the command you use to run Eleventy?

ala-n commented 1 month ago

Sure,

The actual command in root/11ty-package/pacage.json (runs in the context of root/11ty-package) is:

 eleventy --serve --incremental -- --env=development

The -- --env=development part is not directly related to the 11ty server (included just in case it indirectly affects something)

Running through workspaces root (e.g., npm run serve -w 11ty-package) does not affect path resolution.