Join the Webstudio community

Updated 7 months ago

JS libraries via NPM

At a glance

The community member is trying to use the Motion One animation library with Webstudio, but is having trouble importing it. They have successfully used the Anime.js library, but are unsure how to import Motion One, as the documentation only mentions using npm. Other community members suggest using a CDN like jsDelivr or unpkg to access the library without npm. They provide example code for using Motion One with a CDN, but the community member is still unable to get it working. The community members suggest that the issue may be with the way the library is being imported, and provide some alternative approaches, but there is no explicitly marked answer.

Useful resources
Hello, I'm trying out different animation libraries with webstudio. I've gotten anime.js working easily with
Plain Text
<script src="https://cdn.jsdelivr.net/gh/juliangarnier/anime@b471ced746e4488b0e53587bbdd5999f7af2f668/lib/anime.min.js">
</script>

However, I would like to try out motion one before committing to the library. Motion one's docs only say to use npm to install it, however I can't find anywhere on webstudio's documentation how to do this.
How can I import this library?
O
N
11 comments
unpkg gives you examples how to find any library there
Oh amazing thank you, I wasn't able to find any version, let alone the .min version!
With anime.js I have this working script that moves any .element class right when the page loads:
Plain Text
<script src="https://cdn.jsdelivr.net/gh/juliangarnier/anime@b471ced746e4488b0e53587bbdd5999f7af2f668/lib/anime.min.js"></script>

<script>
  anime({
    targets: ".element",
    translateX: 50,
    duration: 1500,
  });
</script>


I took your link here: https://unpkg.com/[email protected]/dist/motion.min.js
and converted it to jsdelivr: https://cdn.jsdelivr.net/npm/[email protected]/dist/motion.min.js

and implemented it in the same way like this:
Plain Text
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/motion.min.js">
</script>

<script>
 import animate from "motion"
 
  animate(".element", { x: 50 }, { duration: 1.5 })
</script>


I must be missing something simple because its not working with or without the import animate from "motion" line
you don't need import there
it should have a globally defined name
alternative is to import from that url using import promise syntax
Its very odd, I've tried a number of other libraries imported the same way and those are working great, just couldn't get this one working. Making good progress with another library now tho, thank you!
this one is fine as well, shouldn't be any problem
Add a reply
Sign up and join the conversation on Discord
However, I would like to try out motion one before committing to the library. Motion one's docs only say to use npm to install it, however I can't find anywhere on webstudio's documentation how to do this.How can I import this library?","url":"https://help.webstudio.is/js-libraries-via-npm-WchmTsMNjN3W","identifier":"WchmTsMNjN3W","publisher":{"@type":"Organization","name":"Webstudio","logo":{"@type":"ImageObject","url":"https://assets.usehall.com/org_01JEYTC8WWMF7N46W9J4J7CFDP/c7f10f06-f934-4e35-b008-431a89254f9f.png"}},"comment":[{"@type":"Comment","text":"you can find npm package e.g. https://www.npmjs.com/package/motion","dateCreated":"2024-07-19T21:36:36.726Z","dateModified":"2024-07-19T21:36:36.726Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":1,"upvoteCount":0},{"@type":"Comment","text":"then go to jsdelivr or https://unpkg.com/","dateCreated":"2024-07-19T21:36:52.728Z","dateModified":"2024-07-19T21:36:52.728Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":2,"upvoteCount":0},{"@type":"Comment","text":"unpkg gives you examples how to find any library there","dateCreated":"2024-07-19T21:37:07.027Z","dateModified":"2024-07-19T21:37:07.027Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":3,"upvoteCount":0},{"@type":"Comment","text":"https://unpkg.com/[email protected]/dist/motion.min.js","dateCreated":"2024-07-19T21:40:06.653Z","dateModified":"2024-07-19T21:40:06.653Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":4,"upvoteCount":0},{"@type":"Comment","text":"all files https://unpkg.com/browse/[email protected]/dist/","dateCreated":"2024-07-19T21:40:17.079Z","dateModified":"2024-07-19T21:40:17.079Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":5,"upvoteCount":0},{"@type":"Comment","text":"Oh amazing thank you, I wasn't able to find any version, let alone the .min version!With anime.js I have this working script that moves any .element class right when the page loads: I took your link here: https://unpkg.com/[email protected]/dist/motion.min.jsand converted it to jsdelivr: https://cdn.jsdelivr.net/npm/[email protected]/dist/motion.min.jsand implemented it in the same way like this: I must be missing something simple because its not working with or without the import animate from \"motion\" line","dateCreated":"2024-07-19T22:30:54.586Z","dateModified":"2024-07-19T22:30:54.586Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/27eea1ed-c1e4-4687-9104-2fcb83c668bc","name":"Nateaúx","identifier":"27eea1ed-c1e4-4687-9104-2fcb83c668bc","image":"https://cdn.discordapp.com/avatars/350916563865698306/795604ca75ea48ee5ff2d42000124796.webp?size=256"},"commentCount":0,"comment":[],"position":6,"upvoteCount":0},{"@type":"Comment","text":"you don't need import there","dateCreated":"2024-07-20T17:39:12.939Z","dateModified":"2024-07-20T17:39:12.939Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":7,"upvoteCount":0},{"@type":"Comment","text":"it should have a globally defined name","dateCreated":"2024-07-20T17:40:01.026Z","dateModified":"2024-07-20T17:40:01.026Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":8,"upvoteCount":0},{"@type":"Comment","text":"alternative is to import from that url using import promise syntax","dateCreated":"2024-07-20T17:40:27.616Z","dateModified":"2024-07-20T17:40:27.616Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":9,"upvoteCount":0},{"@type":"Comment","text":"Its very odd, I've tried a number of other libraries imported the same way and those are working great, just couldn't get this one working. Making good progress with another library now tho, thank you!","dateCreated":"2024-07-21T16:40:43.950Z","dateModified":"2024-07-21T16:40:43.950Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/27eea1ed-c1e4-4687-9104-2fcb83c668bc","name":"Nateaúx","identifier":"27eea1ed-c1e4-4687-9104-2fcb83c668bc","image":"https://cdn.discordapp.com/avatars/350916563865698306/795604ca75ea48ee5ff2d42000124796.webp?size=256"},"commentCount":0,"comment":[],"position":10,"upvoteCount":0},{"@type":"Comment","text":"this one is fine as well, shouldn't be any problem","dateCreated":"2024-07-21T16:41:17.864Z","dateModified":"2024-07-21T16:41:17.864Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/cdd3ed87-53a0-414a-885a-56b7939e412a","name":"Oleg Isonen","identifier":"cdd3ed87-53a0-414a-885a-56b7939e412a","image":"https://cdn.discordapp.com/avatars/469405813048606720/8b66a5882214c63ee6148fcce3ef8e93.webp?size=256"},"commentCount":0,"comment":[],"position":11,"upvoteCount":0}],"author":{"@type":"Person","url":"https://help.webstudio.is/members/27eea1ed-c1e4-4687-9104-2fcb83c668bc","name":"Nateaúx","identifier":"27eea1ed-c1e4-4687-9104-2fcb83c668bc","image":"https://cdn.discordapp.com/avatars/350916563865698306/795604ca75ea48ee5ff2d42000124796.webp?size=256"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0}}]