sql-js / sql-js/sql.js

Problems with browserify

Open
#187 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

This kind of environment selectors destroy browserify (code is shortened for brevity).

if (ENVIRONMENT_IS_NODE) {
  var nodeFS = require('fs');
  var nodePath = require('path');

Browserify resolves the require even if it's inside of the if. Because of this, a big piece of Node.js is Browserified and never used because the code never falls there.

This is a nonsense. Is there any simple workaround to solve this problem inside the library?

It's easy to separate the environment selection in two files, one with the browser part and another with the node part but that's not cool for packaging.

What do you think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Browserify build around the ENVIRONMENT_IS_NODE block and inspect how the require('fs') and require('path') calls are resolved. Define a packaging-compatible way to avoid bundling unused Node.js code, then verify that the browser build succeeds without that code.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, web-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.