本文介绍了Uncaught TypeError:无法设置未定义的属性"[any AMD]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scrollmagic模块示例,但其他模块也是如此.我怀疑这是给Babel的,但不确定.

Example scrollmagic module, but it happens with others too.I suspect it is for Babel but not sure.

我们如何重现此错误?

  1. Git克隆 https://github.com/zurb/foundation-zurb-template 项目名

安装:

  • npm安装gsap --save-dev
  • bower install scrollmagic --save-dev

添加文本行config.yml:

Add text line config.yml:

  • "node_modules/gsap/src/uncompressed/TweenMax.js"
  • "bower_components/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js"
  • "bower_components/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js"
  • "bower_components/scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js"
  • "bower_components/scrollmagic/scrollmagic/uncompressed/plugins/jquery.ScrollMagic.js"

npm start

npm start

发生了什么事?

在控制台Google Chrome中:Uncaught TypeError: Cannot set property 'ScrollMagic' of undefined

In console Google Chrome:Uncaught TypeError: Cannot set property 'ScrollMagic' of undefined

谷歌浏览器:

Firefox:

Firefox:

推荐答案

我找到了问题,但没有解决. - 1个Stackoverflow答案

I found the problem but not solve it. - 1 Answer of Stackoverflow

问题是我在ES6中有文件,而其他没有.是否需要在这里分开文件?怎么样?

The problem is that I have files in ES6 and others not.Would have to separate files here? How?

// Combine JavaScript into one file
// In production, the file is minified
function javascript() {
  return gulp.src(PATHS.javascript)
    .pipe($.sourcemaps.init())
    .pipe($.babel())
    .pipe($.concat('app.js'))
    .pipe($.if(PRODUCTION, $.uglify()
      .on('error', e => { console.log(e); })
    ))
    .pipe($.if(!PRODUCTION, $.sourcemaps.write()))
    .pipe(gulp.dest(PATHS.dist + '/assets/js'));
}

为什么错了?说明...

更改文件javascript.

更改为 未定义

Why wrong? Explanation...

Change the file javascript.

Change this to undefined

} else if (typeof exports === 'object') {

}(this, function () {
    "use strict";

    var ScrollMagic = function () {

} else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {


})(undefined, function () {
    "use strict";

    var ScrollMagic = function ScrollMagic() {

代码片段:

在这样做之前:

Code fragment:

Before doing so:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(factory);
    } else if (typeof exports === 'object') {
        // CommonJS
        module.exports = factory();
    } else {
        // Browser global
        root.ScrollMagic = factory();
    }
}(this, function () {
    "use strict";

    var ScrollMagic = function () {

这样做之后:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(factory);
    } else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
        // CommonJS
        module.exports = factory();
    } else {
        // Browser global
        root.ScrollMagic = factory();
    }
})(undefined, function () {
    "use strict";

    var ScrollMagic = function ScrollMagic() {

这篇关于Uncaught TypeError:无法设置未定义的属性"[any AMD]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 20:30