Incompatability serve-handler dengan versi path-to-regexp #2

Closed
opened 2025-03-10 17:47:19 +07:00 by mario · 0 comments
Owner

Problem

Ketika yarn run build di sansani live, ditemukan issue:

HTTP 3/4/2025 3:42:34 PM 104.28.251.247 GET /
HTTP 3/4/2025 3:42:34 PM 104.28.251.247 Returned 200 in 78 ms
HTTP 3/4/2025 3:42:34 PM 104.28.251.247 GET /app-config.js

INFO Gracefully shutting down. Please wait...
/home/pacs/Viewers/node_modules/serve-handler/src/index.js:81
const toPath = pathToRegExp.compile(normalizedDest);
^

TypeError: pathToRegExp.compile is not a function
at toTarget (/home/pacs/Viewers/node_modules/serve-handler/src/index.js:81:30)
at applyRewrites (/home/pacs/Viewers/node_modules/serve-handler/src/index.js:105:18)
at module.exports (/home/pacs/Viewers/node_modules/serve-handler/src/index.js:618:24)
at async run (file:///home/pacs/Viewers/node_modules/serve/build/main.js:184:7)

Node.js v20.18.3

Penjelasan:

TypeError: pathToRegExp.compile is not a function

is caused by an incompatibility between the serve-handler package (used internally by serve) and the version of path-to-regexp installed in your project. This issue arises because newer versions of path-to-regexp have removed or changed the compile method, which serve-handler relies on.

Solusinya

Modify /home/pacs/Viewers/node_modules/serve-handler/src/index.js

// From this
const toPath = pathToRegExp.compile(normalizedDest);

// To this
const toPath = (params) => normalizedDest.replace(/:([^\/]+)/g, (_, key) => params[key]);
## Problem Ketika `yarn run build` di sansani live, ditemukan issue: ```sh HTTP 3/4/2025 3:42:34 PM 104.28.251.247 GET / HTTP 3/4/2025 3:42:34 PM 104.28.251.247 Returned 200 in 78 ms HTTP 3/4/2025 3:42:34 PM 104.28.251.247 GET /app-config.js INFO Gracefully shutting down. Please wait... /home/pacs/Viewers/node_modules/serve-handler/src/index.js:81 const toPath = pathToRegExp.compile(normalizedDest); ^ TypeError: pathToRegExp.compile is not a function at toTarget (/home/pacs/Viewers/node_modules/serve-handler/src/index.js:81:30) at applyRewrites (/home/pacs/Viewers/node_modules/serve-handler/src/index.js:105:18) at module.exports (/home/pacs/Viewers/node_modules/serve-handler/src/index.js:618:24) at async run (file:///home/pacs/Viewers/node_modules/serve/build/main.js:184:7) Node.js v20.18.3 ``` ## Penjelasan: `TypeError: pathToRegExp.compile is not a function` is caused by an incompatibility between the `serve-handler` package (used internally by `serve`) and the version of `path-to-regexp` installed in your project. This issue arises because newer versions of `path-to-regexp` have removed or changed the `compile` method, which `serve-handler` relies on. ## Solusinya Modify `/home/pacs/Viewers/node_modules/serve-handler/src/index.js` ```js // From this const toPath = pathToRegExp.compile(normalizedDest); // To this const toPath = (params) => normalizedDest.replace(/:([^\/]+)/g, (_, key) => params[key]); ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mario/ohif-viewer#2