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

Can't import retoolrpc using cjs on Node 22 #35

Open
benweissmann opened this issue Oct 28, 2024 · 2 comments
Open

Can't import retoolrpc using cjs on Node 22 #35

benweissmann opened this issue Oct 28, 2024 · 2 comments

Comments

@benweissmann
Copy link

Node 22 read an imported file's nearest package.json to determine whether it's a cjs or mjs module. The retoolrpc package contains a malformed package.json file in dist/cjs/package.json: the contents are "{\"type\":\"commonjs\"}" (double-JSON-encoded; appears to be a bug on this line where you're both explicitly JSON.stringify-ing, and using fs.writeFileJSON).

This causes an error when importing the module with commonjs in Node 22:

Error: Invalid package config .../node_modules/retoolrpc/dist/cjs/package.json.
    at Object.getNearestParentPackageJSON (node:internal/modules/package_json_reader:111:33)
    at node:internal/modules/cjs/loader:1654:35
    at require.extensions..jsx.require.extensions..js (/.../ts-node-dev-hook-12651585434515367.js:114:20)
    at Object.nodeDevHook [as .js] (.../node_modules/ts-node-dev/lib/hook.js:63:13)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.<anonymous> (node:internal/modules/cjs/loader:1340:12)
    at Module.Hook.Module.require (.../node_modules/dd-trace/packages/dd-trace/src/ritm.js:85:33)
@trevoro
Copy link

trevoro commented Oct 29, 2024

@benweissmann Hey I had the same issue. I think this project is DOA from retool's perspective. The lead maintainer left and nobody is really picking it up. To fix the issue I installed patch-package then adde a patch for that file, that replaces the escaped JSON with un-escaped / normal JSON.

You should end up with a patch file like this.

diff --git a/node_modules/retoolrpc/dist/cjs/package.json b/node_modules/retoolrpc/dist/cjs/package.json
index 81cd6a5..5bbefff 100644
--- a/node_modules/retoolrpc/dist/cjs/package.json
+++ b/node_modules/retoolrpc/dist/cjs/package.json
@@ -1 +1,3 @@
-"{\"type\":\"commonjs\"}"
+{
+  "type": "commonjs"
+}

Just set up patch-package so that it runs after npm install and you should be GTG.

@himanshu-bhandoh
Copy link
Contributor

Heads up that I merged a fix here. Please let me know if this works for you @benweissmann + @trevoro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants