-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Context
Hi browserify friends! I'm migrating a monorepo to use pnpm instead of yarn. The monorepo has a frontend package which is bundled with browserify. After migrating from yarn, the application started to throw an error when bundling.
The error happened when attempting to bundle filestack-js:
Error: Can't walk dependency graph: Cannot find module '../../../../../../node_modules/.pnpm/[email protected]/node_modules/is-buffer/index.js' from '../../node_modules/.pnpm/[email protected][email protected]/node_modules/filestack-js/build/browser/filestack.esm.js'
Investigation
The error seems to be related to the is-buffer package, however, it wasn't even a dependency for filestack-js. After some time debugging, it seemed to be related with a call that it does to Buffer.isBuffer. This led me to the insert-module-globals package:
I believe somehow it is not resolving the path correctly. It may be related to the fact that pnpm symlinks the packages. Maybe there's something incorrect when trying resolve the path to is-buffer.
To prove that, if I go to the filestack-js directory:
cd node_modules/.pnpm/[email protected][email protected]/node_modules/filestack-js/build/browser/
And then, if I try requiring that path on the error, I can confirm the same problem occurs:
node -e "console.log(require('../../../../../../node_modules/.pnpm/[email protected]/node_modules/is-buffer/index.js'))"However, the actual path should have been one level lower, meaning this works:
node -e "console.log(require('../../../../../../../node_modules/.pnpm/[email protected]/node_modules/is-buffer/index.js'))"Reproducing
I've put up a repo that can be used to reproduce it: https://github.com/wmartins/browserify-pnpm-investigation.
Current workaround
My current workaround for this is to provide my own implementation of Buffer.isBuffer with insertGlobalVars.
I'm not sure if this should be a browserify/browserify issue or a browserify/insert-module-globals issue, but I've decided to add it here. If this is not the right place, I'm happy to move it.
Do you have any idea how to solve this problem? Is there anything else that I can do?
In case there's something missing or any extra information is needed, I'm happy to provide it!
I can also provide a PR, but honestly I don't have much context on how to navigate it and to point exactly where the issue is.