Skip to content

How to use jsforce ver1.6.0 by webpack #381

Closed

Description

@rchaser53

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?

Activity

  1. stomita commented on Mar 23, 2016

    @stomita
    Contributor

    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.

  2. sgroschupf commented on May 1, 2016

    @sgroschupf

    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.

  3. dirajkumar commented on May 5, 2016

    @dirajkumar

    @stomita I'm having similar issue. Can you please let me how to use webpack and jsforce together?

  4. stomita commented on May 5, 2016

    @stomita
    Contributor

    @sgroschupf @dirajkumar I'll investigate and will include the webpack support in next patch release.

  5. reopened this on May 5, 2016
  6. dirajkumar commented on May 6, 2016

    @dirajkumar

    @stomita You're the best. When is the next release date? I'm really looking forward to it. Thanks a lot again.

  7. stomita commented on May 9, 2016

    @stomita
    Contributor

    @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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions