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

TypeError: Cannot read property '_walk' of null #3274

Closed
Crashthatch opened this issue Oct 10, 2018 · 7 comments · Fixed by #3334
Closed

TypeError: Cannot read property '_walk' of null #3274

Crashthatch opened this issue Oct 10, 2018 · 7 comments · Fixed by #3334

Comments

@Crashthatch
Copy link

Bug report

Uglify fails to minify some code and instead errors with the above error. Seems to be affecting several people using uglify, but I couldn't see an open issue in this repo, so thought I'd bring it to your attention / open this issue to track.

terser/terser#120
ember-cli/ember-cli#8075
angular/angular-cli#12414

There was an old bug from 2017 which was supposedly fixed with the same error message:
#1609

Happens when running uglify from the CLI or through uglifyjs-webpack-plugin

Running with --keep-fnames or adding collapse_vars to the compress webpack config options works around the issue:

        new UglifyJsPlugin({
          uglifyOptions: {
            compress: {
              collapse_vars: false
            },
          }
        })

Uglify version (uglifyjs -V)
3.4.9
(Also tested with 3.3.28 & a few in between, they all error)

JavaScript input

I can't share my company's code, see terser/terser#120 (comment) for a reproducible example.

The uglifyjs CLI command executed or minify() options used.
../../node_modules/.bin/uglifyjs --compress --verbose client-6a7cff1a.js

JavaScript output or error produced.
...<hundreds of warnings because I used --verbose>
WARN: Dropping unused variable gpu [client-6a7cff1a.js:59688,12]
WARN: Dropping unused variable retina [client-6a7cff1a.js:59710,16]
WARN: Collapsing fe [client-6a7cff1a.js:59777,19]
WARN: Dropping unused variable fe [client-6a7cff1a.js:59776,16]
WARN: Collapsing d [client-6a7cff1a.js:59776,21]
WARN: Collapsing e [client-6a7cff1a.js:59775,20]
ERROR: Cannot read property '_walk' of null
at AST_Dot.eval (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :873:29)
at TreeWalker._visit (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :1151:21)
at AST_Dot._walk (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :872:24)
at AST_VarDef.eval (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :820:40)
at TreeWalker._visit (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :1151:21)
at AST_VarDef._walk (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :818:24)
at AST_Var.eval (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :801:32)
at TreeWalker._visit (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :1151:21)
at AST_Var._walk (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :798:24)
at walk_body (eval at (/path/to/my/project/node_modules/uglify-js/tools/node.js:21:1), :448:17)

@ersel
Copy link

ersel commented Oct 12, 2018

We're experiencing the same problem because we depend on tether library. Here is a minimal example:

var xyz = function() {
  var isFullscreenElement = function isFullscreenElement(e) {
    var d = e.ownerDocument;
    var fe = d.fullscreenElement || d.somethingElse
    return fe === e;
  };

  var currentNode = null;
  while(isFullscreenElement(currentNode)){}
}

@ersel
Copy link

ersel commented Oct 12, 2018

this variation works:

var xyz = function() {
  var d;
  var isFullscreenElement = function isFullscreenElement(e) {
    d = e.ownerDocument;
    var fe = d.fullscreenElement && d.somethingElse
    return fe 
  };

  var currentNode = null;
  while(isFullscreenElement(currentNode)){}
}

something to do with closures maybe?

@rjksn
Copy link

rjksn commented Oct 18, 2018

How do we fix this… if we're just using Gulp?

@kaii-zen
Copy link

stream.pipe(uglify({ keep_fnames: true }))

if you don't mind your function names not being obfuscated.

@ersel
Copy link

ersel commented Oct 18, 2018

we made the following config change collapse_vars: false

@NatarajanGanapathi-Hexaware

We are getting the following issue when minify the mysql2 package. I recorded this issue in mysql2 also.

node-mysql2 Issue 899

node_modules/mysql2/lib/commands/index.js []
TypeError: Cannot read property 'replace' of undefined
    at make_string (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:5645:19)
    at encode_string (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:5689:19)
    at Object.print_string (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6107:27)
    at eval (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6396:16)
    at doit (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6168:13)
    at AST_Directive.eval (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6175:13)
    at eval (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6438:22)
    at Array.forEach (<anonymous>)
    at display_body (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6429:14)
    at eval (eval at <anonymous> (/Users/NatarajanG/BitBucket/mission/mission.shrink/node_modules/uglify-es/tools/node.js:21:1), <anonymous>:6463:9) []
node_modules/mysql2/lib/commands/ping.js []

@EmberRed
Copy link

EmberRed commented Feb 2, 2019

same code work for a project and not for the other...
gulp 4.0
error:
Message:
Cannot read property 'minify' of undefined
Details:
domainEmitter: [object Object]
domain: [object Object]
domainThrown: false
any ideas?

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Mar 13, 2019
alexlamsl added a commit that referenced this issue Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants