Giter VIP home page Giter VIP logo

Comments (7)

egorsmkv avatar egorsmkv commented on April 28, 2024 7

@evanw hi, can we also build assets which use standard Node modules?

I have these issues:

yehor@desktop ~/W/Y/yforum2> esbuild --bundle webpack.mix.js  --outdir=dist --minify --sourcemap
node_modules/laravel-mix/src/index.js:19:22: error: Could not resolve "path"
global.path = require('path');
                      ~~~~~~
node_modules/dotenv/lib/main.js:24:19: error: Could not resolve "fs"
const fs = require('fs')
                   ~~~~
node_modules/dotenv/lib/main.js:25:21: error: Could not resolve "path"
const path = require('path')
                     ~~~~~~
node_modules/laravel-mix/src/File.js:1:17: error: Could not resolve "os"
let os = require('os');
                 ~~~~
node_modules/laravel-mix/src/File.js:3:19: error: Could not resolve "path"
let path = require('path');

from esbuild.

egorsmkv avatar egorsmkv commented on April 28, 2024 2

Short answer: yes.

I want to use the esbuild to build my assets for a Laravel project (it's a php framework) and produce a JS file for browsers.

But I think I am applying the esbuild in a wrong place.

from esbuild.

mijime avatar mijime commented on April 28, 2024 2

absolute, ok := r.loadNodeModules(importPath, sourceDirInfo)
if !ok {
// Note: node's "self references" are not currently supported
return "", ResolveMissing
}

It seems that loadNodeModules is not check to packageJson.browserModuleMap.

So, the browser field set module returns ResolveMissing.

from esbuild.

evanw avatar evanw commented on April 28, 2024

Thanks for the report. It looks like my remapping code for the browser field in package.json is relative to the wrong directory. I hadn't discovered this earlier because the packages I tested had all files in the same directory, so it worked even though it was incorrect. This should be easy to fix.

from esbuild.

evanw avatar evanw commented on April 28, 2024

Good question.

The output of esbuild's --bundle option is intended to be used for running in the browser. Not only does it require all of your source code to be in files on disk, but it also uses substitutions in the browser field in package.json files to bundle browser-specific versions of your npm libraries. So it won't work with any npm libraries that use standard node modules.

In my experience, projects that run in node keep the individual source files separate on disk and use require() calls to load the files at run-time instead of bundling them all into a single file at build time. What's your use case for bundling your node project into a single file? Or are you still targeting the browser instead of node and just using some npm libraries that aren't browser-friendly?

from esbuild.

moranje avatar moranje commented on April 28, 2024

To add to the list of use cases of bundeling for Node.js. I currently am developing an Alfred (MacOS App) workflow. Since MacOS does not natively support node I only ask my users to install Node.js and bundle all the other dependencies so users won't have to run an npm install on each update.

Another use case for bundling Node.js would be serverless functions.

However I'm running into same errors as described above

> esbuild dist/workflow/src/alfred-workflow-todoist.js --bundle --minify --sourcemap --outfile=dist/workflow/src/bundle.js
dist/workflow/src/lib/cli-arguments.js:3:23: error: Could not resolve "util"
const util_1 = require("util");
                       ~~~~~~
node_modules/dotenv/lib/main.js:24:19: error: Could not resolve "fs"
const fs = require('fs')
                   ~~~~
node_modules/dotenv/lib/main.js:25:21: error: Could not resolve "path"
const path = require('path')
                     ~~~~~~
node_modules/macos-version/index.js:2:19: error: Could not resolve "fs"
const fs = require('fs');
                   ~~~~
node_modules/clean-stack/index.js:2:19: error: Could not resolve "os"
const os = require('os');
                   ~~~~
dist/workflow/src/lib/logger.js:7:23: error: Could not resolve "util"
const util_1 = require("util");
                       ~~~~~~
dist/workflow/src/lib/workflow/notification.js:3:32: error: Could not resolve "child_process"
const child_process_1 = require("child_process");
                                ~~~~~~~~~~~~~~~
node_modules/got/dist/source/index.js:6:22: error: Could not resolve "url"
const url_1 = require("url");
                      ~~~~~
node_modules/conf/index.js:22:7: error: "require" must not be called indirectly
delete require.cache[__filename];
       ~~~~~~~
node_modules/got/dist/source/as-stream.js:4:23: error: Could not resolve "http"
const http_1 = require("http");
                       ~~~~~~

from esbuild.

mijime avatar mijime commented on April 28, 2024

There is discussion about nodeJS support in #10

from esbuild.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.