Comments (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.
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.
esbuild/src/esbuild/resolver/resolver.go
Lines 66 to 70 in 6e2d798
It seems that loadNodeModules
is not check to packageJson.browserModuleMap
.
So, the browser field set module returns ResolveMissing
.
from esbuild.
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.
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.
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.
There is discussion about nodeJS support in #10
from esbuild.
Related Issues (20)
- Allow for including hostname authority component in stack trace file URIs HOT 3
- Enable picking truly random port in serve mode HOT 7
- Transform doesn't seem to be honoring initialization worker: false HOT 2
- Live Reload still loading when splitting is true and format is esm
- JSX automatic transform imports 'react' with `createElement` HOT 1
- Replicate Babel's `optimizeConstEnums` transformation
- Fails to resolve tsconfig.json `extends` by `exports` field when using yarn pnp HOT 1
- [email protected] prototype setting when bundling json containing a `__proto__` key HOT 3
- Is it possible to customize the [dir] in entryNames?
- Expose directly and indirectly modified files in between builds
- Tree shaking differs between splitting and no splitting
- Simple way to make an esbuild plugin that watches src directory recursively? HOT 2
- Run DCE without minify? HOT 4
- Explanation of colors in Bundle Size Analyzer HOT 1
- Compile to ES6? [Feature request] HOT 2
- Optionally disable CSS selectors renaming in local-css across entrypoints
- Error resolving an external transitive dependency when using pnpm HOT 4
- Import with wildcard HOT 2
- Inside docker, esbuild quietly exits with 0 when --serve is enabled HOT 4
- Build failing in Dockerfile but works on local Windows machine
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esbuild.