Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug recurred: error: Could not resolve "fs" #1364

Closed
n0pj opened this issue Jun 11, 2021 · 6 comments
Closed

Bug recurred: error: Could not resolve "fs" #1364

n0pj opened this issue Jun 11, 2021 · 6 comments

Comments

@n0pj
Copy link

n0pj commented Jun 11, 2021

The bug has recurred on my Mac. #90
It happened when I updated esbuild from 0.12.7 to 0.12.8.

node -v
14.15.0

I using esbuild with gulp, browserify.

    // ...
    return esbuild
      .build({
        define: { 'process.env.NODE_ENV': mode },
        target: 'es6',
        entryPoints: files,
        bundle: true,
        outdir: `${buildDirectorySrc}/scripts`,
        minify: !isDev,
        sourcemap: isDev,
        plugins: [sassPlugin()]
      })
      .catch(e => {
        console.log(e)
        // process.exit(1)
      })
@lxsmnsyc
Copy link

@evanw
Copy link
Owner

evanw commented Jun 25, 2021

This is currently unactionable. There isn't enough information here to be able to reproduce it so it can be fixed. Please provide a way to reproduce the issue.

@evanw
Copy link
Owner

evanw commented Sep 21, 2021

Closing due to lack of a response.

@evanw evanw closed this as completed Sep 21, 2021
@johrstrom
Copy link

Hi can I open this back up? I'm getting it out of the handlebars package while building for the browser.

[ERROR] Could not resolve "fs"

    node_modules/handlebars/lib/index.js:17:19:
      17 │   var fs = require('fs');
         ╵                    ~~~~

https://github.com/handlebars-lang/handlebars.js/blob/a9fe6d5a03cbb4a58ec80806d08c0602435c974c/lib/index.js#L18

Admittedly I'm a bit new the javascript toolchains so I don't know to force this dependency to build one way or another. I don't have a build.js - I'm just running this one command:

esbuild app/javascript/packs/*.* --bundle --sourcemap --loader:.svg=file --outdir=app/assets/builds

@evanw
Copy link
Owner

evanw commented Apr 12, 2022

I assume you are bundling for node because fs is a node-specific API. In that case you should use --platform=node. This is documented: https://esbuild.github.io/getting-started/#bundling-for-node. Or you can just do --external:fs to skip bundling fs if you are bundling for the browser and the code causing the problem is never used (you obviously can’t actually use fs in the browser because it’s a node-only API). Anyway this is not a bug with esbuild. You just need to configure esbuild correctly.

@johrstrom
Copy link

Or you can just do --external:fs to skip bundling fs

This is exactly what I'm looking for. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants