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

Zepto doesn't work with npm and webpack #1324

Open
cyrilchapon opened this issue Dec 21, 2017 · 19 comments
Open

Zepto doesn't work with npm and webpack #1324

cyrilchapon opened this issue Dec 21, 2017 · 19 comments

Comments

@cyrilchapon
Copy link

cyrilchapon commented Dec 21, 2017

This issue was closed #1222 with no reason :)

import $ from 'zepto'

Leads to

Uncaught TypeError: Cannot read property 'createElement' of undefined


The workaround provided, "use master branch" does not work either, since requiring module from github with npm (npm install madrobby/zepto#master) results in a non-built package, that can't be required, then

import $ from 'zepto'

Leads to

Module not found: Error: Can't resolve 'zepto'


This is dead simple, there is no need for any explaination, but a real need for a git merge and an npm publish basically

Requiring a module from the most popular package manager, then using it through the most popular module bundler does seem like a basic requirement for a 13k stars js library in 2017, doesn't it ?

@vacekj
Copy link

vacekj commented Mar 24, 2018

TypeScript support would also be nice!

@shabashj
Copy link

any progress with this?

@vacekj
Copy link

vacekj commented Mar 25, 2018

If you want to use Zepto because it's lighter and less bloated than jQuery, as did I, go with a custom jQuery build. Here are the instructions.
After building it, require (or import) the resulting file inside of your main script, or directly in webpack. With VSCode, you will still have IntelliSense for jQuery, and your build will only contain what you need.

@shabashj
Copy link

OK , thank you.

@cyrilchapon
Copy link
Author

This is insane

@gabriel3000
Copy link

Wtf how is this a thing? I just did exactly as you described. Cant believe it doesn't work that easy. I guess It can be added outside the bundle and then "$" set as a global var.

@vacekj
Copy link

vacekj commented May 12, 2018

Zepto is dead to me because of this. Luckily, you don't really need jQuery anymore, it's easier and less painful to use vanilla js

@nfwyst
Copy link

nfwyst commented May 13, 2018

same to me

@linrock
Copy link

linrock commented Jul 3, 2018

this workaround gets zepto 1.2.0 (latest npm release) working with webpack:

environment.config.module = {
  rules: [
    {
      test: require.resolve("zepto"),
      use: "imports-loader?this=>window"
    }
  ]
}

then to use zepto as a jquery replacement:

environment.config.resolve = {
  alias: {
    jquery: "zepto"
  }
}

need to install the imports-loader webpack plugin first

@AlexMost
Copy link

AlexMost commented Jul 9, 2018

Same for me, simple import breaks everything. Can't use this library.

npm install zepto
node
> require('zepto')
TypeError: Cannot read property 'createElement' of undefined

@volas
Copy link

volas commented Aug 23, 2018

Hi @madrobby, can you look at this?
It's 2 years old version in npm...

@SqrTT
Copy link

SqrTT commented Aug 23, 2018

due to the issue, I had to refuse usage of zepto in a large project

@cyrilchapon
Copy link
Author

To augment sqrTt words, same here, from a CTO

@jbmonroe
Copy link
Contributor

It still has to work in browsers that don't support import or require, doesn't it? I hate to be that guy, but how is it you have time to b1tch about it on GitHub, but you don't have time for a fork-and-fix?

@SqrTT
Copy link

SqrTT commented Oct 10, 2018

but you don't have time for a fork-and-fix?

And then support/maintain for EOL, while the issue is fixed in master just not released to npm.

See #1244

@leefsmp
Copy link

leefsmp commented Oct 29, 2018

Just be realistic about it guys... there is still no valid replacement for jquery 🤣

@jbmonroe
Copy link
Contributor

If you stick to the evergreen browsers, there's almost no need for jQuery. I haven't needed much more than

const $ = s => Array.from(document.querySelectorAll(s));

for years. About 90% of the main-stream jQuery use can be supplied by functions taking the results of $() and using vanilla JS to get the job done.

johannwagner added a commit to johannwagner/golden-layout that referenced this issue Feb 20, 2020
I wrote a new webpack configuration to be able to use the
demo app within the new toolchain.
I also removed some obscure resolves and fixed Webpack HMR.

The current version does not work with zepto.
madrobby/zepto#1324
I am not willing to do this workaround. Maybe, there will
be a zepto version in near future.
martin31821 pushed a commit to golden-layout/golden-layout that referenced this issue Apr 15, 2020
I wrote a new webpack configuration to be able to use the
demo app within the new toolchain.
I also removed some obscure resolves and fixed Webpack HMR.

The current version does not work with zepto.
madrobby/zepto#1324
I am not willing to do this workaround. Maybe, there will
be a zepto version in near future.
@paxperscientiam
Copy link

paxperscientiam commented Jun 10, 2021

Works for Me with fuse-box, which is built on typescript and so allows for synthetic imports.

import 'zepto/src/zepto'
import 'zepto/src/event'
import 'zepto/src/fx'

document.addEventListener("DOMContentLoaded", function(event) {
    Zepto("#hi")
        .animate({
        opacity: 0.25, left: '50px',
        color: '#abcdef',
        rotateZ: '45deg', translate3d: '-100px,-100px,-100px'
    }, 10000, 'ease-out')
})

EDIT: I was originally importing the whole thing plus fx. The correct way to do it is to import zepto.js, event.js, and fx.js for the given example.

Something missing from the docs is that these modules have some level of inter-dependency. EG, fx.js depends on events.js

@Sleepful
Copy link

Sleepful commented Nov 29, 2022

what a waste of time to attempt using zepto....
I finally get it working the way @paxperscientiam described, and....
I can't even do a query by ID because apparently the id has some forbidden character (the # i suppose? no idea)
something that isn't an issue with document.getElementById, unbelievable.....

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

No branches or pull requests