question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'end' of null

See original GitHub issue

Bug Report

Current Behavior

I’m getting the following error when trying to minify a large file outputted by TypeScript.

TypeError: dist/main.js: Cannot read property 'end' of null
    at _evaluate (node_modules/babel-traverse/lib/path/evaluation.js:160:58)
    at evaluate (node_modules/babel-traverse/lib/path/evaluation.js:65:17)
    at NodePath.evaluate (node_modules/babel-traverse/lib/path/evaluation.js:41:15)
    at evaluateIdentifier (node_modules/babel-helper-evaluate-path/lib/index.js:127:15)
    at evaluate (node_modules/babel-helper-evaluate-path/lib/index.js:19:12)
    at PluginPass.Expression (node_modules/babel-plugin-minify-constant-folding/lib/index.js:165:21)
    at PluginPass.newFn (node_modules/babel-traverse/lib/visitors.js:318:17)
    at newFn (node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (node_modules/babel-traverse/lib/path/context.js:48:17)

I’ve tracked it down to #4875 which introduces an if statement that compares path.node.start with binding.path.node.end. Note that one side is comparing a property on path, and the other on binding.path.

Changing the right-hand side to path.node.end seems to fix the issue.

Input Code Unfortunately, I discovered this in a closed source repo…

Expected behavior/code I expected the file to be minified and translated to ES2015.

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": ["es2015", "minify"],
  "comments": false
}
babel dist/main.js --out-file dist/main.min.js

Environment

  • Babel version(s): 6.26.0 (babel-core 6.26.0)
  • Node/npm version: Node v10.0.0, npm v5.6.0
  • OS: macOS 10.13.4
  • Monorepo: no
  • How you are using Babel: cli

Possible Solution

diff --git a/node_modules/babel-traverse/lib/path/evaluation.js b/node_modules/babel-traverse/lib/path/evaluation.js
index d608418..c05b833 100644
--- a/node_modules/babel-traverse/lib/path/evaluation.js
+++ b/node_modules/babel-traverse/lib/path/evaluation.js
@@ -156,7 +156,7 @@ function evaluate() {
         return deopt(binding.path);
       }
 
-      if (binding && path.node.start < binding.path.node.end) {
+      if (binding && path.node.start < path.node.end) {
         return deopt(binding.path);
       }
 

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
kyhcommented, Oct 13, 2018

I was running into the same issue and I managed to fix it by changing my babel-preset-minify version from 0.5.0 -> 0.3.0

0reactions
zgr024commented, Oct 21, 2018

.babelrc

{
  "presets": ["env", "stage-2"],
  "env": {
    "production": {
      "presets": ["minify"]
    }
  }
}

package.json

...
"scripts": {
    "build": "babel src -d build --source-maps inline",
    "build:dist": "NODE_ENV=production babel src -d dist",
    ...
},
"dependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-minify": "^0.5.0",
    "babel-preset-stage-2": "^6.24.1",
    "babel-register": "^6.26.0",
    ...
}

$ npm run builld:dist

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "Cannot read property 'pickAlgorithm' of null" error in ...
Running npm cache clear --force. Environment: OS: Windows 10 react native: 0.65.1. Node: 14.17.4 npm: 7.21.0.
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns...
Read more >
Uncaught TypeError: Cannot read property 'end' of null / range ...
Uncaught TypeError : Cannot read property 'end' of null / range is null. Open, Needs TriagePublic. Actions.
Read more >
Uncaught TypeError: Cannot read property of undefined In
This error occurs in Chrome Browser when you read a property or call a method on an undefined object . There are a...
Read more >
Client Exception Uncaught TypeError: Cannot read property ...
Client Exception Uncaught TypeError : Cannot read property 'getFieldType' of null - when editing or creating new item. FootPrints ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found