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

Module not found: Can't resolve './crypto/build/Release/sshcrypto.node' #775

Open
manuel-rw opened this issue Jul 27, 2024 · 7 comments
Open

Comments

@manuel-rw
Copy link

manuel-rw commented Jul 27, 2024

Similar to #759

node v20.11.1
pnpm 9.6.0

image

When we import Dockerode from a TS file

import Docker from "dockerode";

we get this error occasionally:

@homarr/nextjs:dev: 2024-07-27T16:16:53.527Z warn:  ⚠ ../../node_modules/ssh2/lib/protocol/crypto.js
@homarr/nextjs:dev: Module not found: Can't resolve './crypto/build/Release/sshcrypto.node' in 'C:\Users\manue\WebstormProjects\homarr\node_modules\ssh2\lib\protocol'
@homarr/nextjs:dev:
@homarr/nextjs:dev: Import trace for requested module:
@homarr/nextjs:dev: ../../node_modules/ssh2/lib/protocol/crypto.js
@homarr/nextjs:dev: ../../node_modules/ssh2/lib/server.js
@homarr/nextjs:dev: ../../node_modules/ssh2/lib/index.js
@homarr/nextjs:dev: ../../packages/api/node_modules/docker-modem/lib/ssh.js
@homarr/nextjs:dev: ../../packages/api/node_modules/docker-modem/lib/modem.js
@homarr/nextjs:dev: ../../packages/api/node_modules/dockerode/lib/docker.js
@homarr/nextjs:dev: ../../packages/api/src/router/docker/docker-singleton.ts
@homarr/nextjs:dev: ../../packages/api/src/router/docker/docker-router.ts
@homarr/nextjs:dev: ../../packages/api/src/root.ts
@homarr/nextjs:dev: ../../packages/api/src/index.ts
@homarr/nextjs:dev: ./src/app/api/trpc/[trpc]/route.ts

Functionality does not seem to be affected, but the warning is annoying.

next.config.mjs

// Importing env files here to validate on build
import "@homarr/auth/env.mjs";
import "./src/env.mjs";

/** @type {import("next").NextConfig} */
const config = {
  output: "standalone",
  reactStrictMode: true,
  /** We already do linting and typechecking as separate tasks in CI */
  eslint: { ignoreDuringBuilds: true },
  typescript: { ignoreBuildErrors: true },
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.module.rules.push({
        test: /\.node$/,
        loader: "node-loader",
      });
    }

    return config;
  },
  experimental: {
    optimizePackageImports: ["@mantine/core", "@mantine/hooks", "@tabler/icons-react"],
    serverComponentsExternalPackages: ["dockerode"],
  },
  transpilePackages: ["@homarr/ui", "@homarr/notifications", "@homarr/modals", "@homarr/spotlight", "@homarr/widgets"],
  images: {
    domains: ["cdn.jsdelivr.net"],
  },
};

export default config;

We use server side components & the app directory.

@danstarns
Copy link

danstarns commented Aug 25, 2024

+1

@danstarns
Copy link

ssh2

Fixed by manually installing ssh2:

pnpm add ssh2

@manuel-rw
Copy link
Author

ssh2

Fixed by manually installing ssh2:

pnpm add ssh2

Thanks for the comment, but this doesn't fully solve the error in a project referencing dockerode as a dependency.
I get a slightly different trace now:

@homarr/nextjs:dev: Module not found: Can't resolve './crypto/build/Release/sshcrypto.node' in 'C:\Users\XXXXXXX\XXXXXXXXX\homarr\node_modules\ssh2\lib\protocol'
@homarr/nextjs:dev:
@homarr/nextjs:dev: Import trace for requested module:
@homarr/nextjs:dev: ../../node_modules/ssh2/lib/protocol/crypto.js
@homarr/nextjs:dev: ../../node_modules/ssh2/lib/protocol/keyParser.js
@homarr/nextjs:dev: ../../node_modules/ssh2/lib/index.js
@homarr/nextjs:dev: ../../packages/api/node_modules/docker-modem/lib/ssh.js
@homarr/nextjs:dev: ../../packages/api/node_modules/docker-modem/lib/modem.js
@homarr/nextjs:dev: ../../packages/api/node_modules/dockerode/lib/docker.js
@homarr/nextjs:dev: ../../packages/api/src/router/docker/docker-singleton.ts
@homarr/nextjs:dev: ../../packages/api/src/router/docker/docker-router.ts
@homarr/nextjs:dev: ../../packages/api/src/root.ts
@homarr/nextjs:dev: ../../packages/api/src/index.ts
@homarr/nextjs:dev: ../../packages/api/src/server.ts

git --no-pager diff

diff --git a/package.json b/package.json
index 48194bc6..bf5e0f3d 100644
--- a/package.json
+++ b/package.json
@@ -48,5 +48,8 @@
     "patchedDependencies": {
       "[email protected]": "patches/[email protected]"
     }
+  },
+  "dependencies": {
+    "ssh2": "^1.15.0"
   }
 }
\ No newline at end of file
diff --git a/packages/api/package.json b/packages/api/package.json
index 782e0a28..683d7402 100644
--- a/packages/api/package.json
+++ b/packages/api/package.json
@@ -41,6 +41,7 @@
     "dockerode": "^4.0.2",
     "next": "^14.2.11",
     "react": "^18.3.1",
+    "ssh2": "^1.15.0",
     "superjson": "2.2.1",
     "trpc-swagger": "^1.2.6"
   },
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4ab21413..8a34e3a5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -12,6 +12,10 @@ patchedDependencies:
 importers:
 
   .:
+    dependencies:
+      ssh2:
+        specifier: ^1.15.0
+        version: 1.15.0
     devDependencies:
       '@homarr/prettier-config':
         specifier: workspace:^0.1.0
@@ -21,10 +25,10 @@ importers:
         version: 2.1.2(@types/[email protected])([email protected])
       '@vitejs/plugin-react':
         specifier: ^4.3.1
-        version: 4.3.1([email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))
+        version: 4.3.1([email protected](@types/[email protected])([email protected])([email protected])([email protected]))
       '@vitest/coverage-v8':
         specifier: ^2.1.1
-        version: 2.1.1([email protected](@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))
+        version: 2.1.1([email protected](@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected]))
       '@vitest/ui':
         specifier: ^2.1.1
         version: 2.1.1([email protected])
@@ -48,10 +52,10 @@ importers:
         version: 5.6.2
       vite-tsconfig-paths:
         specifier: ^5.0.1
-        version: 5.0.1([email protected])([email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))
+        version: 5.0.1([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))
       vitest:
         specifier: ^2.1.1
-        version: 2.1.1(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected])
+        version: 2.1.1(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])

   apps/nextjs:
     dependencies:
@@ -515,6 +519,9 @@ importers:
       react:
         specifier: ^18.3.1
         version: 18.3.1
+      ssh2:
+        specifier: ^1.15.0
+        version: 1.15.0
       superjson:
         specifier: 2.2.1
         version: 2.2.1
@@ -9567,18 +9574,18 @@ snapshots:
       global: 4.4.0
       is-function: 1.0.2

-  '@vitejs/[email protected]([email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))':
+  '@vitejs/[email protected]([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':
     dependencies:
       '@babel/core': 7.24.6
       '@babel/plugin-transform-react-jsx-self': 7.24.5(@babel/[email protected])
       '@babel/plugin-transform-react-jsx-source': 7.24.1(@babel/[email protected])
       '@types/babel__core': 7.20.5
       react-refresh: 0.14.2
-      vite: 5.2.11(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])
+      vite: 5.2.11(@types/[email protected])([email protected])([email protected])([email protected])
     transitivePeerDependencies:
       - supports-color

-  '@vitest/[email protected]([email protected](@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))':
+  '@vitest/[email protected]([email protected](@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected]))':
     dependencies:
       '@ampproject/remapping': 2.3.0
       '@bcoe/v8-coverage': 0.2.3
@@ -9592,7 +9599,7 @@ snapshots:
       std-env: 3.7.0
       test-exclude: 7.0.1
       tinyrainbow: 1.2.0
-      vitest: 2.1.1(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected])
+      vitest: 2.1.1(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])
     transitivePeerDependencies:
       - supports-color

@@ -9603,13 +9610,13 @@ snapshots:
       chai: 5.1.1
       tinyrainbow: 1.2.0

-  '@vitest/[email protected](@vitest/[email protected])([email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))':
+  '@vitest/[email protected](@vitest/[email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':
     dependencies:
       '@vitest/spy': 2.1.1
       estree-walker: 3.0.3
       magic-string: 0.30.11
     optionalDependencies:
-      vite: 5.2.11(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])
+      vite: 5.2.11(@types/[email protected])([email protected])([email protected])([email protected])

   '@vitest/[email protected]':
     dependencies:
@@ -9639,7 +9646,7 @@ snapshots:
       sirv: 2.0.4
       tinyglobby: 0.2.6
       tinyrainbow: 1.2.0
-      vitest: 2.1.1(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected])
+      vitest: 2.1.1(@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected])

   '@vitest/[email protected]':
     dependencies:
@@ -14146,12 +14153,12 @@ snapshots:
     dependencies:
       global: 4.4.0

-  [email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]):
+  [email protected](@types/[email protected])([email protected])([email protected])([email protected]):
     dependencies:
       cac: 6.7.14
       debug: 4.3.7
       pathe: 1.1.2
-      vite: 5.2.11(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])
+      vite: 5.2.11(@types/[email protected])([email protected])([email protected])([email protected])
     transitivePeerDependencies:
       - '@types/node'
       - less
@@ -14162,18 +14169,18 @@ snapshots:
       - supports-color
       - terser

-  [email protected]([email protected])([email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected])):
+  [email protected]([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])):
     dependencies:
       debug: 4.3.5
       globrex: 0.1.2
       tsconfck: 3.0.3([email protected])
     optionalDependencies:
-      vite: 5.2.11(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])
+      vite: 5.2.11(@types/[email protected])([email protected])([email protected])([email protected])
     transitivePeerDependencies:
       - supports-color
       - typescript

-  [email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]):
+  [email protected](@types/[email protected])([email protected])([email protected])([email protected]):
     dependencies:
       esbuild: 0.20.2
       postcss: 8.4.45
@@ -14185,10 +14192,10 @@ snapshots:
       sugarss: 4.0.1([email protected])
       terser: 5.32.0

-  [email protected](@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]):
+  [email protected](@types/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])([email protected]):
     dependencies:
       '@vitest/expect': 2.1.1
-      '@vitest/mocker': 2.1.1(@vitest/[email protected])([email protected](@types/[email protected])([email protected])([email protected]([email protected]))([email protected]))
+      '@vitest/mocker': 2.1.1(@vitest/[email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))
       '@vitest/pretty-format': 2.1.1
       '@vitest/runner': 2.1.1
       '@vitest/snapshot': 2.1.1
@@ -14203,8 +14210,8 @@ snapshots:
       tinyexec: 0.3.0
       tinypool: 1.0.0
       tinyrainbow: 1.2.0
-      vite: 5.2.11(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])
-      vite-node: 2.1.1(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])
+      vite: 5.2.11(@types/[email protected])([email protected])([email protected])([email protected])
+      vite-node: 2.1.1(@types/[email protected])([email protected])([email protected])([email protected])
       why-is-node-running: 2.3.0
     optionalDependencies:
       '@types/node': 20.16.5

@jabedzaman
Copy link

got any solution???

@class-undefined
Copy link

+1, same issue here.

@luizfelipelaviola
Copy link

Same issue here

@teremy
Copy link

teremy commented Nov 7, 2024

Not sure if this will help (it helped me). I installed "node-loader" (npm install node-loader) and configured it for .node-files in the Webpack config.
So your next.config.ts will look something like this:

const nextConfig: NextConfig = {
  webpack: (
    config,
    { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
  ) => {
    config.module.rules.push({
      test: /\.node$/,
      loader: "node-loader",
    });

    // Important: return the modified config
    return config
  },
};

export default nextConfig;

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

6 participants