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

Error: Can't walk dependency graph if a dependency has the same name like node builtin #1986

Open
jkroepke opened this issue Nov 5, 2020 · 5 comments
Assignees

Comments

@jkroepke
Copy link

jkroepke commented Nov 5, 2020

Ref: cisco/node-jose#301

A 3rd party library of our application using a process shim. https://www.npmjs.com/package/process

If found, browserify raise an error that the module or file can't not be find:

npx browserify -e src/index.js -o dist/lib.js
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat '/Users/jkr/Downloads/s/process'
    required by /Users/jkr/Downloads/s/src/index.js

For some reasons, browserify is looking on top level directory instead node_modules.

How to reprocde:

  1. Run npm install process
  2. Create a file with content: const process = require('process')
  3. Run npx browserify index.js
@ljharb
Copy link
Member

ljharb commented Nov 5, 2020

In that case, require('process') will refer to the core module. If your file wants to pull in an installed package with that name, it needs to do require('process/').

@jkroepke
Copy link
Author

jkroepke commented Nov 5, 2020

I test few versions from browserify and I could figure out that this change is somewhere between 16.5.1 and 16.5.2

Running browserify 16.5.1 works fine while 16.5.2 not. Is this expected?

Is this new? Reading https://github.com/browserify/browserify/releases I could not see any big changes.

Pin browserify could a workaround now but is isn't a lifetime solution.

Looks like #1973 introduce a bc breaking change which released as patch version.

@ljharb
Copy link
Member

ljharb commented Nov 5, 2020

Certainly this may be a breaking change, but I think this may also be a bugfix. require('process') in node always gives the core module; if you want to force the process shim, you'd always need require('process/'). That said, I would expect the command in your OP to work, precisely because it never actually requires the process shim.

@jkroepke
Copy link
Author

jkroepke commented Nov 6, 2020

precisely because it never actually requires the process shim.

In that case, setting browser: {process : false} inside package.json could be a rescue here, too. Thanks.

Edit: After test above, the setting does not work anymore, no matter if I set browser: {process : false} or browser: {process : "node_modules/process/browser.js"}.

@jkroepke
Copy link
Author

The current workaround is to place a file called process without file extension on the root directory.

In my case, put

module.exports = {"browser": true}

is good enough here. In other situations, a full process shim is may required. -> https://www.npmjs.com/package/process

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