Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Runs on the browser? #82

Closed
jhs opened this issue Jul 29, 2015 · 14 comments
Closed

Runs on the browser? #82

jhs opened this issue Jul 29, 2015 · 14 comments

Comments

@jhs
Copy link
Contributor

jhs commented Jul 29, 2015

No build, no distribution, just get the code working from a browser as an alpha release.

@jhs jhs added this to the Browser 1.0 milestone Jul 29, 2015
@jhs
Copy link
Contributor Author

jhs commented Jul 29, 2015

Follow is out of scope

@abhishiv
Copy link

Maybe find a way to build it via webpack?

Right now it seems to break because of this line in nano.

@glynnbird
Copy link
Contributor

The master branch of nodejs-cloudant now depends on 6.1.5 of Nano which should support webpack.

@glynnbird
Copy link
Contributor

I'm not familiar with webpack but I had a go. I created a webpack.config.js file:

module.exports = {
    entry: "./cloudant.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.json$/, loader: "json"}       ]
    }
};

and ran webpack, which returned the following errors:

ERROR in ./~/nano/~/request/lib/har.js
Module not found: Error: Cannot resolve module 'fs' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/lib
 @ ./~/nano/~/request/lib/har.js 3:9-22

ERROR in ./~/nano/~/request/~/forever-agent/index.js
Module not found: Error: Cannot resolve module 'net' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/node_modules/forever-agent
 @ ./~/nano/~/request/~/forever-agent/index.js 6:10-24

ERROR in ./~/nano/~/request/~/forever-agent/index.js
Module not found: Error: Cannot resolve module 'tls' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/node_modules/forever-agent
 @ ./~/nano/~/request/~/forever-agent/index.js 7:10-24

ERROR in ./~/nano/~/request/~/tough-cookie/lib/cookie.js
Module not found: Error: Cannot resolve module 'net' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/node_modules/tough-cookie/lib
 @ ./~/nano/~/request/~/tough-cookie/lib/cookie.js 32:10-24

ERROR in ./~/nano/~/request/~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'net' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/node_modules/tunnel-agent
 @ ./~/nano/~/request/~/tunnel-agent/index.js 3:10-24

ERROR in ./~/nano/~/request/~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'tls' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/node_modules/tunnel-agent
 @ ./~/nano/~/request/~/tunnel-agent/index.js 4:10-24

ERROR in ./~/nano/~/request/~/har-validator/~/is-my-json-valid/~/jsonpointer/jsonpointer.js
Module not found: Error: Cannot resolve module 'console' in /Users/glynnb/projects/nodejs-cloudant/node_modules/nano/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/jsonpointer
 @ ./~/nano/~/request/~/har-validator/~/is-my-json-valid/~/jsonpointer/jsonpointer.js 1:14-32

As this library depends on Nano, which depends on Request which depends on "fs", I think that's me stumped!

@glynnbird
Copy link
Contributor

Work in progress is in the 'webpack' branch

@abhishiv
Copy link

Hey Glynn

If you add the following to your webpack config, webpack with mock these node modules, and you should be able to compile without any errors.

    node: {
        console: true,
        fs: 'empty',
        net: 'empty',
        tls: 'empty',
        __filename: true,
        __dirname: true
    }

However, it throws up the following error when you try to use it

Uncaught TypeError: self._qs.unescape is not a function

It seems to be related to request/request#1619, but I too am lost on how to make it work.

@abhishiv
Copy link

Got it to work - with a hack, but still..

Just do this before requiring this library.

import {Querystring} from "request/lib/querystring.js";
Querystring.prototype.unescape = function(val) {
    return val // TODO should unescape it
};

Should be able to run without this hack after mike-spainhower/querystring#4 is closed.

@glynnbird
Copy link
Contributor

Querystring.prototype.unescape = function(val) {
    return unescape(val);
};

?

@abhishiv
Copy link

Yeah that works, was just being lazy.

@glynnbird
Copy link
Contributor

@abhishiv would you mind publishing your HTML showing how you are requiring this bundle, including the Querystring work-around?

@abhishiv
Copy link

Hey Glynn

What exactly do you want to check?

I am actually planning to use this module in a project, however that isn't public as of yet.

However I have pushed abhishiv/nodejs-cloudant@5dc4f0c8d78f6b5955f5ee45542281789803bcc0 which contains a complete webpack config and a webpack script.

If you run node ./webpack.js in that branch, you'll have the bundle at http://localhost:3500/static/bundle.js.

I'm not actually sure where the qs fix should go. Since my project uses request as well, I just patch it before requiring nodejs-cloudant. But in this case I think it should go into nano - because nano is the one which actually requires request.

@glynnbird
Copy link
Contributor

I'm just looking for some sample HTML that includes the bundle, patches it and makes it all work ;)

@abhishiv
Copy link

Ah understood, I just pushed an example at abhishiv/cloudant-node-webpack-consumer.

You just need to set a password in src/index.js and add your domain to the CORS section in your cloudant dashboard.

@smithsz smithsz removed this from the Browser 1.0 milestone Nov 14, 2017
@ricellis
Copy link
Member

Closing, we're not planning to do this. If further browser support requirements materialize we should address them in cloudant-node-sdk.

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

No branches or pull requests

5 participants