apocas / dockerode

Docker + Node = Dockerode (Node.js module for Docker's Remote API)
Apache License 2.0
4.39k stars 465 forks source link

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

Open manuel-rw opened 3 months ago

manuel-rw commented 3 months ago

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 commented 2 months ago

+1

danstarns commented 2 months ago

ssh2

Fixed by manually installing ssh2:

pnpm add ssh2
manuel-rw commented 2 months ago

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": {
       "trpc-swagger@1.2.6": "patches/trpc-swagger@1.2.6.patch"
     }
+  },
+  "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/node@20.16.5)(typescript@5.6.2)
       '@vitejs/plugin-react':
         specifier: ^4.3.1
-        version: 4.3.1(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))
+        version: 4.3.1(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))
       '@vitest/coverage-v8':
         specifier: ^2.1.1
-        version: 2.1.1(vitest@2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))
+        version: 2.1.1(vitest@2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))
       '@vitest/ui':
         specifier: ^2.1.1
         version: 2.1.1(vitest@2.1.1)
@@ -48,10 +52,10 @@ importers:
         version: 5.6.2
       vite-tsconfig-paths:
         specifier: ^5.0.1
-        version: 5.0.1(typescript@5.6.2)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))
+        version: 5.0.1(typescript@5.6.2)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))
       vitest:
         specifier: ^2.1.1
-        version: 2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+        version: 2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)

   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/plugin-react@4.3.1(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))':
+  '@vitejs/plugin-react@4.3.1(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))':
     dependencies:
       '@babel/core': 7.24.6
       '@babel/plugin-transform-react-jsx-self': 7.24.5(@babel/core@7.24.6)
       '@babel/plugin-transform-react-jsx-source': 7.24.1(@babel/core@7.24.6)
       '@types/babel__core': 7.20.5
       react-refresh: 0.14.2
-      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)
     transitivePeerDependencies:
       - supports-color

-  '@vitest/coverage-v8@2.1.1(vitest@2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))':
+  '@vitest/coverage-v8@2.1.1(vitest@2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))':
     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/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vitest: 2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)
     transitivePeerDependencies:
       - supports-color

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

-  '@vitest/mocker@2.1.1(@vitest/spy@2.1.1)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))':
+  '@vitest/mocker@2.1.1(@vitest/spy@2.1.1)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))':
     dependencies:
       '@vitest/spy': 2.1.1
       estree-walker: 3.0.3
       magic-string: 0.30.11
     optionalDependencies:
-      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)

   '@vitest/pretty-format@2.1.1':
     dependencies:
@@ -9639,7 +9646,7 @@ snapshots:
       sirv: 2.0.4
       tinyglobby: 0.2.6
       tinyrainbow: 1.2.0
-      vitest: 2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vitest: 2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)

   '@vitest/utils@2.1.1':
     dependencies:
@@ -14146,12 +14153,12 @@ snapshots:
     dependencies:
       global: 4.4.0

-  vite-node@2.1.1(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0):
+  vite-node@2.1.1(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0):
     dependencies:
       cac: 6.7.14
       debug: 4.3.7
       pathe: 1.1.2
-      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)
     transitivePeerDependencies:
       - '@types/node'
       - less
@@ -14162,18 +14169,18 @@ snapshots:
       - supports-color
       - terser

-  vite-tsconfig-paths@5.0.1(typescript@5.6.2)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)):
+  vite-tsconfig-paths@5.0.1(typescript@5.6.2)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)):
     dependencies:
       debug: 4.3.5
       globrex: 0.1.2
       tsconfck: 3.0.3(typescript@5.6.2)
     optionalDependencies:
-      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)
     transitivePeerDependencies:
       - supports-color
       - typescript

-  vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0):
+  vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0):
     dependencies:
       esbuild: 0.20.2
       postcss: 8.4.45
@@ -14185,10 +14192,10 @@ snapshots:
       sugarss: 4.0.1(postcss@8.4.45)
       terser: 5.32.0

-  vitest@2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0):
+  vitest@2.1.1(@types/node@20.16.5)(@vitest/ui@2.1.1)(jsdom@25.0.0)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0):
     dependencies:
       '@vitest/expect': 2.1.1
-      '@vitest/mocker': 2.1.1(@vitest/spy@2.1.1)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0))
+      '@vitest/mocker': 2.1.1(@vitest/spy@2.1.1)(vite@5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0))
       '@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/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
-      vite-node: 2.1.1(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1(postcss@8.4.45))(terser@5.32.0)
+      vite: 5.2.11(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)
+      vite-node: 2.1.1(@types/node@20.16.5)(sass@1.78.0)(sugarss@4.0.1)(terser@5.32.0)
       why-is-node-running: 2.3.0
     optionalDependencies:
       '@types/node': 20.16.5
jabedzaman commented 1 month ago

got any solution???

class-undefined commented 4 weeks ago

+1, same issue here.

luizfelipelaviola commented 4 weeks ago

Same issue here

teremy commented 2 weeks ago

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;