I have used jsforce ver1.5.1 in my project.
Recently I tryed to update jsforce 1.6.0 but I failed to bundle the source using webpack.
Error messeage is below.
ERROR in ./~/jsforce/lib/cli/cli.js
Module not found: Error: Cannot resolve module 'repl' in * node_modules path *
@ ./~/jsforce/lib/cli/cli.js 40:86-101
ERROR in ./~/commander/index.js
Module not found: Error: Cannot resolve module 'child_process' in * node_modules path *
@ ./~/commander/index.js 6:12-36
How should I do?
It seems webpack is not correctly handling package's metadata field browser, so it will lookup module which is unavailable in browser environment. Use browserify for building browser module instead.
Hi Stomita,
I have the same problem here.
Can you be more clear about what to do to resolve this. I can not switch my build to browsify, since I have a more complex project.
Any help would be appreciated.
@stomita I'm having similar issue. Can you please let me how to use webpack and jsforce together?
@sgroschupf @dirajkumar I'll investigate and will include the webpack support in next patch release.
@stomita You're the best. When is the next release date? I'm really looking forward to it. Thanks a lot again.
@dirajkumar @sgroschupf ver 1.6.3 is out and it has webpack bundling support. You need webpack.config.js with loader json-loader explicitly to create bundle without error.
module.exports = {
//...
module: {
loaders: [
{ test: /\.json$/, loader: "json" }
]
}
};
In the bundling script you can do simply call require('jsforce'):
var jsforce = require('jsforce');
// you can simply create a connection instance
var conn = new jsforce.Connection();
// or you can use browser client object (which is only available in browser env).
jsforce.browser.init({
clientId: 'your oauth2 client id is here',
redirectUri: 'your oauth2 redirect uri is here'
});
jsforce.browser.login();
jsforce.browser.on('connect', function(conn) {
// ...
});
Or you can use require('jsforce/core') to reduce the bundle size
// this only loads core script (without api modules)
var jsforce = require('jsforce/core');
// load chatter api module explicitly
require('jsforce/lib/api/chatter');
var conn = new jsforce.Connection();
console.log(conn.bulk) // undefined
console.log(conn.analytics) // undefined
console.log(conn.chatter) // [object]
Most helpful comment
@dirajkumar @sgroschupf ver 1.6.3 is out and it has webpack bundling support. You need
webpack.config.jswith loaderjson-loaderexplicitly to create bundle without error.In the bundling script you can do simply call
require('jsforce'):Or you can use
require('jsforce/core')to reduce the bundle size