ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.43k stars 1.25k forks source link

App crashes on runtime bundling with webpack: `Error: Cannot find module './fetch.node'` #4285

Closed pablomendezroyo closed 1 year ago

pablomendezroyo commented 1 year ago

Severity:

Critical. NodeJS app crashes at runtime. App built with webpack

Description:

Steps to reproduce the error:

Create node app and build with webpack ("webpack": "^5.52.0",) and the following webpack.config.js

import path from "path";
import webpack from "webpack";
import { fileURLToPath } from "url";
const { NODE_ENV = "production" } = process.env;

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
  entry: "./src/index.ts",
  mode: NODE_ENV,
  target: "node",
  output: {
    path: path.resolve(__dirname, "build"),
    filename: "index.js"
  },
  // externals: [/node_modules/, "bufferutil", "utf-8-validate"],
  resolve: {
    extensions: [".ts", ".js"],
    fallback: {
      electron: false
    }
  },
  module: {
    rules: [
      {
        test: /\.m?js/,
        resolve: {
          fullySpecified: false
        }
      },
      {
        test: /\.ts$/,
        use: ["ts-loader"]
      },
      {
        test: /\.node$/,
        loader: "node-loader"
      }
    ]
  },
  plugins: [
    new webpack.ProvidePlugin({
      WebSocket: "ws",
      fetch: ["node-fetch", "default"]
    })
  ],
  optimization: {
    // Minimization does not provide great disk space savings, but reduces debug capacity
    minimize: false
  },
  devtool: "source-map"
};
welcome[bot] commented 1 year ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

pablomendezroyo commented 1 year ago

I managed to make it work by patching the library ipfs-utils. Not sure what the issue is but my guess is that setting the lib to be exported in a let var is not good. I've modified the files:

For anyone interested, checkout this commit https://github.com/dappnode/DNP_DAPPMANAGER/pull/1341/commits/37ac71b14d17ff4eb143da2760498a91e6d37435

hubingliang commented 1 year ago

i got same issue when i use next13 build app hope fix asap

HappySean2845 commented 1 year ago

Same issue when using NextJS 13.2.1 , ipfs-http-client 60.0.0

rocky-fleek commented 1 year ago

Same issue here with next 13.2.3 :/

alex-nax commented 1 year ago

Same issue, next 13.2.4

apostgit commented 1 year ago

Issue still exists. Can someone give a solution or work around as this doesn't let us complete a functions.

achingbrain commented 1 year ago

js-IPFS is in the process of being deprecated, the replacement is Helia - please see the State of IPFS in JS post for a bit of background and the migration guide for how to port your app over.

You're using ipfs-http-client - if you are talking to a Kubo node, please use kubo-rpc-client instead and open any issues there.

There are examples for using Helia with popular bundlers and frameworks, they have working config you can copy/paste so hopefully these are helpful:

If not, please open an issue on the examples repo for examples you'd like to see.