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

问题描述

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

我们如何重现此错误?

  1. Git克隆

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

     //将JavaScript合并为一个文件//在生产中,文件已缩小函数javascript(){返回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.

    更改为 未定义

    除此之外:

     }否则,如果(typeof输出==='对象'){}(this,function(){使用严格";var ScrollMagic = function(){ 

     }否则if(((typeofexports ==='undefined'?'undefined':_typeof(exports))==='object'){})(未定义,函数(){使用严格";var ScrollMagic = function ScrollMagic(){ 

    代码片段:

    在这样做之前:

     (function(root,factory){if(typeof define ==='function'& define.amd){//AMD.注册为匿名模块.定义(工厂);} else if(typeof exports ==='object'){//CommonJSmodule.exports = factory();} 别的 {//浏览器全局root.ScrollMagic = factory();}}(this,function(){使用严格";var ScrollMagic = function(){ 

    这样做之后:

     (function(root,factory){if(typeof define ==='function'& define.amd){//AMD.注册为匿名模块.定义(工厂);}否则if(((typeofexports ==='undefined'?'undefined':_typeof(exports))==='object'){//CommonJSmodule.exports = factory();} 别的 {//浏览器全局root.ScrollMagic = factory();}})(未定义,函数(){使用严格";var ScrollMagic = function ScrollMagic(){ 

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

    How can we reproduce this bug?

    1. Git clone https://github.com/zurb/foundation-zurb-template projectname

    2. Install:

      • npm install gsap --save-dev
      • bower install scrollmagic --save-dev
    3. 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"
    4. npm start

    What happened instead?

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

    Google Chrome:

    Firefox:

    解决方案

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

    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'));
    }
    

    Why wrong? Explanation...

    Change the file javascript.

    Change this to undefined

    Besides this:

    } else if (typeof exports === 'object') {
    
    }(this, function () {
        "use strict";
    
        var ScrollMagic = function () {
    

    to

    } 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 () {
    

    After doing so:

    (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() {
    

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

05-21 07:22