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

Browserify fails to resolve default node module used within an external package #2077

Open
Abdullah-03 opened this issue Apr 4, 2024 · 7 comments

Comments

@Abdullah-03
Copy link

When the command "browserify main.js -o bundle.js" is run for main.js (see below)

const google = require('googleapis')

async function runSample() {
  const drive = google.drive({
    version: 'v2',
    headers: {
      Authorization: `Bearer authToken`,
    },
  })

  // Make an authorized request to list Drive files.
  const res = await drive.files.list()

  return res
}

runSample().catch(console.error)

it throws the error:

Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\project\process'
required by C:\project\node_modules\googleapis-common\build\src\http2.js

Browserify seems to be looking in the wrong directory for the module, what gives?

These are the imports of the 'node_modules\googleapis-common\build\src\http2.js' file, which uses the node:process module:

Object.defineProperty(exports, "__esModule", { value: true });
exports.closeSession = exports.request = exports.sessions = void 0;
const http2 = require("http2");
const zlib = require("zlib");
const url_1 = require("url");
const qs = require("qs");
const extend = require("extend");
const stream_1 = require("stream");
const util = require("util");
const process = require("process");
const common_1 = require("gaxios/build/src/common");
const { HTTP2_HEADER_CONTENT_ENCODING, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_METHOD, HTTP2_HEADER_PATH, HTTP2_HEADER_STATUS, } = http2.constants;
const DEBUG = !!process.env.HTTP2_DEBUG;
@mikixing

This comment was marked as spam.

@ljharb
Copy link
Member

ljharb commented Apr 4, 2024

It's using process, not node:process - but that's a global and shouldn't need to be required at all, but i'd also expect that to work fine.

Can you provide the full stack trace from the error?

@Abdullah-03
Copy link
Author

Abdullah-03 commented Apr 4, 2024

Those the only lines of error I get, can you explain how to get full stack trace? Is there a flag for it?

@ljharb
Copy link
Member

ljharb commented Apr 4, 2024

hm, not that i know of. if you edit that line on disk (just temporarily) to require the require of process, does everything work?

@Abdullah-03
Copy link
Author

const process = require(require("process"));

Same error as before.

@ljharb
Copy link
Member

ljharb commented Apr 4, 2024

oh sorry i meant "remove" :-p like delete that line entirely

@Abdullah-03
Copy link
Author

lol, was wondering what that would achieve.

Ok, now after removing that line, it compiles bundle.js

very strange.

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