Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生产环境构建devtool必须加入cheap-module-eval-source-map,否则报错 #108

Closed
hxlhxl opened this issue Jul 8, 2019 · 3 comments
Labels

Comments

@hxlhxl
Copy link

hxlhxl commented Jul 8, 2019

Webpack4开发环境没问题,生产环境报错。devtool改变为开发环境的cheap-module-eval-source-map错误消失。
下面是截图:
eruda

@surunzi
Copy link
Member

surunzi commented Jul 15, 2019

试了下,没发现报错,有没有示例代码?

@kurdupovk
Copy link

kurdupovk commented Jul 30, 2019

Hello,
I have encountered the same problem - with Webpack4 on load eruda script it gives me:

0.7996a05a.chunk.js:formatted:2293 Uncaught (in promise) TypeError: ze is not a function
    at 0.7996a05a.chunk.js:formatted:2293
    at Object.<anonymous> (0.7996a05a.chunk.js:formatted:2314)
    at Object.<anonymous> (0.7996a05a.chunk.js:formatted:2378)
    at n (0.7996a05a.chunk.js:formatted:16)
    at Object.<anonymous> (0.7996a05a.chunk.js:formatted:3876)
    at n (0.7996a05a.chunk.js:formatted:16)
    at Object.<anonymous> (0.7996a05a.chunk.js:formatted:6924)
    at n (0.7996a05a.chunk.js:formatted:16)
    at Object.<anonymous> (0.7996a05a.chunk.js:formatted:6633)
    at n (0.7996a05a.chunk.js:formatted:16)

Which leads to the line with code(unminified):
var localStorage = safeStorage('local');

I checked minified version of eruda(that webpack/webpack plugins minified) and found this code:

t.safeStorage = v.safeStorage = function(e) {
                        return {}
                    }())

I.e. safeStorage is initialized as an empty object not a function This is not expected and error happens.

How to solve problem?

var safeStorage = exports.safeStorage = _.safeStorage = function (exports) {
    /* Safe localStorage and sessionStorage.
     */

    /* dependencies
     * isUndef memStorage
     */

    function exports(type, memReplacement) {
        if (isUndef(memReplacement)) memReplacement = true;

        var ret = void 0;

        switch (type) {
            case 'local':
                ret = window.localStorage;
                break;
            case 'session':
                ret = window.sessionStorage;
                break;
        }

        try {
            // Safari private browsing
            var x = 'test-localStorage-' + Date.now();
            ret.setItem(x, x);
            var y = ret.getItem(x);
            ret.removeItem(x);
            if (y !== x) throw new Error();
        } catch (e) {
            if (memReplacement) return memStorage;
            return;
        }

        return ret;
    }

    return exports;
}({});

Function exports that is returned, must be renamed to other name, it conflicts with the argument with the same name that is passed to a function and by the way this argument is empty object. I suspect that a code minifier during minification removes expected function and replace it with empty object.

Good news: I have changed function name and no error happens on that line in code.
Bad news: error happens in other place with similar behavior(empty object returned instead of a function). I suspect there are multiple places with similar behavior.

UPDATE: The next bug with getFileName function - it has also returned function with exports name that conflicts with argument name

@surunzi surunzi added the bug label Aug 2, 2019
This was referenced Aug 2, 2019
@surunzi surunzi closed this as completed in 12daf83 Aug 2, 2019
@surunzi surunzi reopened this Aug 2, 2019
@surunzi
Copy link
Member

surunzi commented Aug 2, 2019

@hxlhxl @kurdupovk Fixed, try v1.5.8

@surunzi surunzi closed this as completed Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants