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

Could not resolve dependency #5

Closed
daveroberts opened this issue Feb 14, 2020 · 7 comments
Closed

Could not resolve dependency #5

daveroberts opened this issue Feb 14, 2020 · 7 comments

Comments

@daveroberts
Copy link

$ esbuild --bundle --outdir=dist --minify --sourcemap src/main.js 
node_modules/axios/lib/defaults.js:23:22: error: Could not resolve "./adapters/http"
    adapter = require('./adapters/http');

1 error
$ ls -l node_modules/axios/lib/adapters/http.js 
-rwxr-xr-x. 1 daver daver 9308 Jan 27 09:42 node_modules/axios/lib/adapters/http.js
@evanw
Copy link
Owner

evanw commented Feb 15, 2020

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.

@evanw evanw closed this as completed in 6e2d798 Feb 15, 2020
@egorsmkv
Copy link

egorsmkv commented Feb 16, 2020

@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');

@evanw
Copy link
Owner

evanw commented Feb 16, 2020

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?

@egorsmkv
Copy link

egorsmkv commented Feb 16, 2020

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.

@mijime
Copy link

mijime commented Feb 21, 2020

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.

@moranje
Copy link

moranje commented Mar 6, 2020

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");
                       ~~~~~~

@mijime
Copy link

mijime commented Mar 7, 2020

There is discussion about nodeJS support in #10

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

No branches or pull requests

5 participants