Giter Site home page Giter Site logo

Export issue about clientjs HOT 11 CLOSED

jackspirou avatar jackspirou commented on July 21, 2024
Export issue

from clientjs.

Comments (11)

jackspirou avatar jackspirou commented on July 21, 2024

Hi @lehaBay thanks for creating this issue.

You mean this line in the minified version correct? https://github.com/jackspirou/clientjs/blob/master/dist/client.min.js#L21

from clientjs.

jackspirou avatar jackspirou commented on July 21, 2024

Ah yes... I found it in the original UAParser source:

if(typeof module!==UNDEF_TYPE&&module.exports){
    exports=module.exports=UAParser
}
exports.UAParser=UAParser

I wonder if its best to simply remove those lines or remove typeof exports === 'object' in the ClientJS source.

Thoughts?

from clientjs.

lehaBay avatar lehaBay commented on July 21, 2024

I think typeof exports === 'object' should be replaced with typeof exports !== "undefined"

but actually there is one more problem.
there is a line from minified version:
if ("undefined" !== typeof exports)"undefined" !== typeof module && module.exports && (exports = module.exports = q), exports.UAParser = q; else {
f.UAParser = q;

so, window.UAParser isn't set if 'exports' is defined so this line throws an error:
e = (new UAParser).getResult();

from clientjs.

lehaBay avatar lehaBay commented on July 21, 2024

@jackspirou

so it works if replace
e = (new UAParser).getResult();
with
e = (new (window.UAParser||exports.UAParser)).getResult();

and replace typeof exports === 'object' in the ClientJS with typeof exports !== 'undefined'

and one more thing, looks like library installed using npm is older than one in repository. It doesn't have getCustomFingerprint method

from clientjs.

jackspirou avatar jackspirou commented on July 21, 2024

@lehaBay I ended up replacing the minified versions with the regular source code in the vendors directories since those get minified anyway by the build.sh bash script.

After reviewing the comments from the regular source it looks like the code that was causing the issue is optional so I commented it out. You can find it here: https://github.com/jackspirou/clientjs/blob/master/src/vendor/ua-parser.js#L866

As for exports === 'object' i took your suggestion and replaced it with exports !== "undefined".

Also I updated the npm registry with the latest version numbers that also include these changes.

Let me know what you think and if we still need to make some changes or if we can close this issue. Thanks!

from clientjs.

lehaBay avatar lehaBay commented on July 21, 2024

@jackspirou i'm having this error now "Uncaught ReferenceError: UAParser is not defined", what i mentioned in the comment above resolves this and everything else is fine now

from clientjs.

jackspirou avatar jackspirou commented on July 21, 2024

@lehaBay the code you have suggested in the comment above (without markup) is in reference to the minified version. Im glad you got the minified version to work, but really we should be updating the source file, namely src/client.js and the vendor file src/vendor/ua-parser.js which is why I referenced it above.

from clientjs.

lehaBay avatar lehaBay commented on July 21, 2024

@jackspirou ok, i thought it's easy to find this line in the sources. here it is:
https://github.com/jackspirou/clientjs/blob/master/src/client.js#L139

just replace var parser = new UAParser(); with var parser = new (window.UAParser||exports.UAParser);

from clientjs.

jackspirou avatar jackspirou commented on July 21, 2024

@lehaBay it wasn't obvious to me 😜

Thanks for sticking through this issue and helping me get this to work with requirejs. I don't use this project with requirejs myself, so its great to have someone give feedback.

I made the updates and now we are on npm clientjs version 0.1.8. Let me know if we are good with requrejs now :)

from clientjs.

lehaBay avatar lehaBay commented on July 21, 2024

@jackspirou Now it's fine, thank you for fixing it, i found another issue with getCustomFingerprint but i'll create a new one because it's not related to this one

from clientjs.

jackspirou avatar jackspirou commented on July 21, 2024

@lehaBay Awesome thanks again for your help!

from clientjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.