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

Node.js - Adding module.exports #124

Open
alex-w0 opened this issue Dec 13, 2017 · 11 comments
Open

Node.js - Adding module.exports #124

alex-w0 opened this issue Dec 13, 2017 · 11 comments
Assignees

Comments

@alex-w0
Copy link

alex-w0 commented Dec 13, 2017

Please use in your library the function module.exports to allow requiring the module with the es6 command "import"

http://stackabuse.com/how-to-use-module-exports-in-node-js/

@dkern
Copy link
Owner

dkern commented Dec 13, 2017

Hello @DevelGitH,

I know how module.exports work. But as Lazy is a client-side script, what should I export? Could you give me an example what you want to be exported and how you use it? I'm open for any improvement!

@alex-w0
Copy link
Author

alex-w0 commented Dec 13, 2017

Hi @eisbehr- ,
thank´s for your answear. Yeah thats true, that you cannot export your library, when you have a client-side script. A solution would be to put your code into a object class or function and afterwards you can export the function with module.exports.

The problem is when i`m trying to import your lazy-load script, it throws an error at the line 43 of the file jquery.lazy.js ($.fn is not defined), because the variable window.$ from the main script couldn´t be passed to your script.

My Code is the following:

//Import jQuery Library
import $ from 'jquery';
window.$ = window.jQuery = $;

import './lib/jquery.lazy';
$("img.lazy").Lazy();

@dkern dkern removed the question label Dec 15, 2017
@dkern
Copy link
Owner

dkern commented Dec 15, 2017

I will keep this open as an enhancement. But I need to think about the implementation.

@massprogressive
Copy link

massprogressive commented Aug 16, 2018

Hi,
I'm using Zurb Foundation CLI, installed it via npm and tried:

import 'jquery-lazy';

copied file to lib folder and tried:

import import './lib/jquery.lazy';

these solutions doesn't work for me, I get this error:

Uncaught TypeError: Cannot read property 'fn' of undefined

How can I import library to my project?

@dkern
Copy link
Owner

dkern commented Aug 17, 2018

The error sounds like you didn't added jQuery to your project, because fn is only used register the plugin within jQuery.

@massprogressive
Copy link

I've used the same import approach as if the first comment:

import $ from 'jquery';
window.$ = window.jQuery = $;

@dkern
Copy link
Owner

dkern commented Aug 17, 2018

Do you know that this is an issue and it is still open? Why do you think it will work for you, if it would not work for others?!

@massprogressive
Copy link

The only solution that I found was pasting import statements on top of the jquery.lazy.js file:

import $ from 'jquery';
window.$ = window.jQuery = $;

/*!
 * jQuery & Zepto Lazy - v1.7.9
 * http://jquery.eisbehr.de/lazy/
 *
 * Copyright 2012 - 2018, Daniel 'Eisbehr' Kern
 *
 * Dual licensed under the MIT and GPL-2.0 licenses:
 * http://www.opensource.org/licenses/mit-license.php

Now it works for me and hope will work for others.

@alex-w0
Copy link
Author

alex-w0 commented Aug 19, 2018

Yeah but that solution wouldn't be nice. The jquery library will now be imported twice, when the developer is using the library in his project. Have a look at other libraries, they aren't importing the required libs in their project.

@dkern
Copy link
Owner

dkern commented Aug 20, 2018

Yes, I know that problem. In the new version of Lazy the import problem is solved and there is no dependency on jQuery anymore. But I can't actually tell when the release will be ready. I think I will publish the first draft within the next time.

@eistruhe
Copy link

Unfortunately this is still an issue. Any news on the new version?

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

No branches or pull requests

4 participants