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

Why can't browserify find this npm module? #2046

Open
TheDiscordian opened this issue Oct 27, 2022 · 3 comments
Open

Why can't browserify find this npm module? #2046

TheDiscordian opened this issue Oct 27, 2022 · 3 comments

Comments

@TheDiscordian
Copy link

Hello, sorry if this is the wrong place to ask, but I'm tearing my hair out over this. For the life of me, browserify won't acknowledge an installed module:

% npm install -g browserify
% . ~/.bash_profile
% npm install --save ipfs-http-client
% browserify main.js        
Error: Can't walk dependency graph: Cannot find module 'ipfs-http-client' from '/Users/disco/Programming/DiscoChat/browserify-sadness/main.js'
    required by /Users/disco/Programming/DiscoChat/browserify-sadness/main.js
    at /opt/homebrew/lib/node_modules/browserify/node_modules/resolve/lib/async.js:146:35
    at processDirs (/opt/homebrew/lib/node_modules/browserify/node_modules/resolve/lib/async.js:299:39)
    at isdir (/opt/homebrew/lib/node_modules/browserify/node_modules/resolve/lib/async.js:306:32)
    at /opt/homebrew/lib/node_modules/browserify/node_modules/resolve/lib/async.js:34:69
    at FSReqCallback.oncomplete (node:fs:211:21)

main.js

var IpfsHttpClient = require('ipfs-http-client');

async function onload() {
	ipfs = await IpfsHttpClient.create({url: "http://127.0.0.1:5001", timeout: "5m"});

	// try to get our peerid
	try {	
		me = await ipfs.id();
	} catch { // if we fail, try again in 1 second
		setTimeout(function(){onload()}, 1000);
		return;
	}

	document.getElementById("status").innerHTML = "Kubo node is running, PeerID: " + me.id.toString();
}

The example in the README works fine, but if I follow the exact same steps with ipfs-http-client it can't even find it.

@goto-bus-stop
Copy link
Member

it doesn't have a main entry point specified in package.json, only an exports field. browserify doesn't support the newer exports field, but it also doesn't support ES modules, so the module may not work with browserify at all.

@PanagiotisDrakatos
Copy link

PanagiotisDrakatos commented Mar 25, 2023

@goto-bus-stop I resepect your experience and i need your help i am facing a similar issue with another module node-java.

% npm install -g browserify
% . ~/.bash_profile
% npm install --save java
% browserify src/java.js -p esmify --standalone mybundle > bundle.js

This is the java.js file

#!/usr/bin/env node
const java = require("java");
function myfunc2() {
    java.classpath.push(__dirname +"/adrestus-crypto-1.0-SNAPSHOT-jar-with-dependencies.jar")
    var mnemonic = "example1";
    var passphrase = "pass";
    var result = java.callStaticMethodSync("io.Adrestus.crypto.WalletAddressExport", "getAddressFromMnemonic", mnemonic, passphrase);
    return result;
}
module.exports = {
    myfunc2,
};

When i load the bundle from html code i got this error

Uncaught Error: Cannot find module '/node_modules/java/build/Release/nodejavabridge_bindings.node'

Does my module also not supported with browserfy or its something different? what are your thoughts?

@goto-bus-stop
Copy link
Member

It's a slightly different issue. The OP is trying to use a package that probably fundamentally works in the browser, but browserify lacks support for ES modules, so it can't be used.

The java package requires using the local filesystem and executing native code, which is fundamentally impossible in the browser and can never work. There is no way to do that in the browser. This is generally true any time you see an error about a .node file, because .node files are native code.

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

No branches or pull requests

3 participants