aos icon indicating copy to clipboard operation
aos copied to clipboard

Uncaught TypeError: Cannot set property 'AOS' of undefined

Open chancer4 opened this issue 6 years ago • 17 comments

Getting an error when trying to install AOS. Console leads me to line 8 which is the first function in the aos.js file. !function (e, t) { "object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "object" == (typeof module === "undefined" ? "undefined" : _typeof(module)) ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) ? exports.AOS = t() : e.AOS = t(); } am using the JS in the dist/ folder from the master branch. Not sure what else I am doing wrong. Please advise.

chancer4 avatar Sep 11 '18 15:09 chancer4

Please use the next version and let me know if you still experience this problem, if yes - how does your environment look like, how do you import AOS on the page, what browser etc.? master branch has been frozen for some time, I'm operating on v2 and next - once v3 is released next will become master again.

michalsnik avatar Oct 04 '18 00:10 michalsnik

Same issue, I installed AOS from npm (npm install --save aos@next) and include library in my HTML and I get aos.js:1 Uncaught TypeError: Cannot set property 'AOS' of undefined

Installed 3.0.0-beta.6

dacmail avatar Oct 18 '18 14:10 dacmail

That is the issue if I use ES6 module directly from the browser, i.e.:

<script type="module" src="app.mjs"></script>

app.mjs

import "../node_modules/aos/dist/aos.js";

AOS will try to set AOS to this, which, inside ES6 module, is undefined, and not window.

I also attempted to use dist/aos-esm.js, but it does not bundle lodash.*, preventing it from being loaded.

An option is to rollup using iife format instead of umd. Alternatively, with the es6 bundle, do not declare the dependencies as external in rollup.config.js.

sntran avatar Nov 05 '18 16:11 sntran

This issue when module not imported check all files and repleted files and module after try again. if have wiry comment.

manojgohel avatar Dec 26 '18 11:12 manojgohel

what is the resolution of this? I've experiencing the same issue. I've concat' the dist file with my script file and aos appears before my code.

kisonay avatar Jun 14 '19 00:06 kisonay

Any update on this? I'm getting the same error.

Error: undefined is not an object (evaluating 'e.AOS=t()')

I'm using gulp to concat my files and minify them. Everything works well when importing the CSS and js scripts via CDN. Below are the CDN scripts I'm using.

https://unpkg.com/aos@next/dist/aos.js https://unpkg.com/[email protected]/dist/aos.css

I can't have external dependencies and wanted to simply copy and paste the CSS and js code from the script tags and place the code in their own local js and CSS files; however, I can't get rid of the error above. The issue is occurring on Safari, Firefox, and Chrome.

NicolasPerl avatar Aug 12 '19 17:08 NicolasPerl

You get that error when using

<script type="module" src="app.js"></script>

but not without the module-type:

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

thgross avatar Oct 15 '19 15:10 thgross

@thgross That's correct. ES6 module is loaded differently than normal script.

sntran avatar Oct 15 '19 16:10 sntran

Hey guys is there any update here as to what possibly causes this? I installed via npm and am getting this error. I have successfully installed both slick and parallax.js via npm. So not quite sure why AOS is giving me an issue.

ineptian avatar Feb 16 '21 23:02 ineptian

I was running into an issue where Babel was transpiling the file under these settings:

options: {
  sourceMap: true,
  presets: ['@babel/preset-env', {}],
  targets: '> 0.25%, not dead, not ie 11, not android 4.4.3-4.4.4'
},

Preventing the transpile of the /dist/aos.js file fixed the issue for me.

Jollus174 avatar Aug 31 '22 03:08 Jollus174

Hello gyes, I am getting same issue, I try many ways, but facing still same issue aos.js:1 Uncaught TypeError: Cannot set properties of undefined (setting 'AOS')

anyone help me to solve this, I really appreciate

naeemariyan avatar Feb 08 '23 06:02 naeemariyan

broo, this is from a year ago but it's weird because I'm also having the same issue. I tried: import * as AOS from "./node_modules/aos/dist/aos.js";, it was working fine, but then I'm still getting errors. It's night time now, I'll be working on this tomorrow, so I hope you're around.

CarlosGT7274 avatar Feb 08 '23 06:02 CarlosGT7274

Imho AOS shouldn't use this so it gets ES6 module compatible. ES6 is the future.

bavarianbytes avatar Feb 08 '23 07:02 bavarianbytes

broo, this is from a year ago but it's weird because I'm also having the same issue. I tried: import * as AOS from "./node_modules/aos/dist/aos.js";, it was working fine, but then I'm still getting errors. It's night time now, I'll be working on this tomorrow, so I hope you're around.

OK, thanks. Please share with me if you find any solution.

naeemariyan avatar Feb 08 '23 15:02 naeemariyan

Imho AOS shouldn't use this so it gets ES6 module compatible. ES6 is the future.

Bro I am using ES6. How can I replace "this" with another value?

naeemariyan avatar Feb 08 '23 15:02 naeemariyan

I think you can't. It is in the AOS library. The author has to change it or someone else has to fork the repo, rewrite it and create a pull request. Unfortunately i'am not so deep in the topic to do so.

bavarianbytes avatar Feb 08 '23 15:02 bavarianbytes

Facing the same error in Nuxt3

Foddie2 avatar Feb 23 '24 08:02 Foddie2