xpl / ololog

A better console.log for the log-driven debugging junkies
https://www.npmjs.com/package/ololog
The Unlicense
215 stars 8 forks source link

Non browser compatible node-module required #23

Open hlolli opened 3 years ago

hlolli commented 3 years ago

For reasons too long to explain here, I can't include browser compatible polyfills for built-in nodejs modules.

So when I'm compiling targeting the browser with rollup I'm getting

[!] Error: Could not load util (imported by node_modules/stacktracey/stacktracey.js): ENOENT: no such file or directory, open 'util'
Error: Could not load util (imported by node_modules/stacktracey/stacktracey.js): ENOENT: no such file or directory, open 'util'

perhaps some easy isBrowser will fix this. I'm also sure that it should be possible to find require ('util').inspect browserified (using built-in modules if in nodejs env).

xpl commented 3 years ago

Could you provide a reproducible example as a github repo (I'm too lazy to configure rollup)?

xpl commented 3 years ago

Could you please check if the issue is gone with the latest published version of Ololog?

hlolli commented 3 years ago

Sorry for not replying, mix of lazyness and busy on my side. I will test today!

hlolli commented 3 years ago

So I tested the changes, I got the exact same error

[!] Error: Could not load util (imported by node_modules/stacktracey/stacktracey.js): ENOENT: no such file or directory, open 'util'
Error: Could not load util (imported by node_modules/stacktracey/stacktracey.js): ENOENT: no such file or directory, open 'util'

to be sure it's new version, I looked into node_modules at the package.json version "version": "1.1.164",

So I just made a reproduceable example repo which actually starts with a different error message, as I've already made a browserify global alias for nodejs's path module (this I can't do with all modules as I have dependencies which require their own fs and util for example).

./index.ejs → index.js...
[!] Error: Could not load path (imported by node_modules/stacktracey/stacktracey.js): ENOENT: no such file or directory, open 'path'
Error: Could not load path (imported by node_modules/stacktracey/stacktracey.js): ENOENT: no such file or directory, open 'path'

This you can test out here https://github.com/hlolli/ololog_bug using the command yarn build. The two plugins (which are potentially the culprits) are @rollup/plugin-node-resolve for putting the node_modules into scope, and @rollup/plugin-commonjs for importing commonjs modules as es module.

xpl commented 3 years ago

Thank you for the repro, I'll look into it in the coming days.