0

I want to use locomotive.js on my project and have installed it on vscode (npm install locomotive-scroll) and have even followed this tutorial:

https://www.youtube.com/watch?v=zrM6N-G6U_M&list=PLNf1MNtmy_vyQkFjuNqxKpQT0U_rbC_y8&index=19

My problem is that I get an error saying:

Uncaught SyntaxError: Cannot use import statement outside a module

I have no idea what to do. I have done some research on compilers and stuff like that but I don't think the tutorial mentioned any of that. It was literally: install, copy, paste and you're good to go.

Here's the script:

import LocomotiveScroll from 'locomotive-scroll';

const scroll = new LocomotiveScroll({
    el: document.querySelector('[data-scroll-container]'),
    smooth: true
});

and to link it to my html:

<script src="index.js"></script>

Any help or ideas would be appreciated.

Hamza Khan
  • 67
  • 9
  • you forgot the `type="module"` inside the script tag or use from dist folder like [this](https://github.com/locomotivemtl/locomotive-scroll#or-without) – User863 Jan 18 '21 at 13:42
  • Does this answer your question? ["Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6](https://stackoverflow.com/questions/58211880/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-import) – User863 Jan 18 '21 at 13:43
  • @User863 adding type="module" leads to an error and using it in the Html leads to more errors. I'm really stuck now – Hamza Khan Jan 18 '21 at 13:53
  • @User863 Never mind I managed to fix it. Thanks for the help though. – Hamza Khan Jan 18 '21 at 13:59

0 Answers0