question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non browser compatible node-module required

See original GitHub issue

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).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hlollicommented, Nov 11, 2020

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.

0reactions
xplcommented, Nov 12, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publishing packages that can be used in browsers and Node
If you want to create a package that's usable in both browsers and Node, this article is here to help.
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
CommonJS modules are the original way to package JavaScript code for Node.js. Node.js also supports the ECMAScript modules standard used by browsers and ......
Read more >
How to write modules that are both nodejs compatible and ...
I am writing a node module {collection of modules}and in future this might be ported to browser environments too. For that reason I...
Read more >
Use this One-Liner to Make any Node.js Module Run in a Web ...
You can convert a node module to its web-browser-compatible version with this single shell command: (Of course, you need to have myNodeModule already ......
Read more >
browserify/browserify: browser-side require() the node.js way
compatibility. Many npm modules that don't do IO will just work after being browserified. Others take more work. Many node built-in modules ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found