Fix: Resolve 'Buffer is not defined' error for mobile devices (android)#266
Fix: Resolve 'Buffer is not defined' error for mobile devices (android)#266onefckcps wants to merge 1 commit intojames-tindal:mainfrom
Conversation
…ompatibility Adjusted build configuration (Webpack, tsconfig, package.json) to prevent runtime errors related to the missing Node.js 'Buffer' global in non-Node environments like Obsidian mobile.
|
Thanks. What is the ts-node loader supposed to do? Looks like markmap is depending on |
|
Hey! You're right, I also tried reverting the build script back to just
Through a quick search I figured out: When The So, it's specifically needed to handle the initial loading of the I am a newcomer to TypeScript, webpack, and Obsidian plugin development, so please correct me if I am wrong or if I misunderstand something :) |
|
The latest version of Node supports a limited set of typescript features. Works fine for me. How did you get Android Obsidian to run the unpublished plugin? |
|
I just compiled the project and moved the plugin files (main.js, manifest.js, style.css) in the plugin folder (.obsidian/plugins/obsidian-mindmap-nextgen/) and restarted the app. For mobile debugging i have used this method: https://docs.obsidian.md/Plugins/Getting+started/Mobile+development#Android That way i was able to see the console errors |
|
Instead of polyfilling Buffer, I'm working on removing gray-matter. Will get this fixed as soon as I can. Thanks for pointing me in the right direction. |
1317043 to
106752e
Compare
Fix: Resolve 'Buffer is not defined' error for browser/mobile compatibility
Problem:
This PR addresses a
ReferenceError: Buffer is not definedthat occurs when running the plugin in non-Node.js environments, such as Obsidian mobile (tested on Android) or potentially web browsers. This error prevents the plugin from loading or functioning correctly in these environments.Solution:
The root cause appears to be the build configuration targeting or assuming a Node.js environment. This leads to issues when dependencies (potentially
gray-matteror others involved in processing) rely on Node-specific globals likeBuffer.This PR adjusts the build configuration files (
webpack.config.ts,tsconfig.json,package.json) to produce a build compatible with standard browser/JavaScript environments whereBufferis not natively available. The primary change involved ensuring the Webpack build does not explicitly target Node.js.Testing:
Manually tested on an Android tablet where the error previously occurred consistently. After applying these changes and rebuilding, the plugin loads and functions without the
Bufferreference error.Related Issues:
(Optional: If this PR fixes an existing issue reported on the original repository, uncomment and replace
#issue_numberbelow)