Minify: TypeError: Cannot read property 'isPure' of null

Created on 3 Feb 2018  路  8Comments  路  Source: babel/minify

Input Code

Repo : https://github.com/jy95/torrent-files-library/tree/5b771ae69dd9b796b30a1147bedc25cd085af09d
Changes not commited : Just added "babel-preset-minify": "^0.3.0" in my package.json and updated my .babelrc.js like this

let env = process.env.BABEL_ENV || process.env.NODE_ENV;
let presets = [];
let plugins = ["@babel/plugin-proposal-object-rest-spread"];
let ignore = ["src/docs/**/*.js"];
let comments = false;

// custom settings for prod/test ; for example babel-istanbul-plugin , etc.
switch (env){
  case 'test':
    // ./fix-coverage/arrow-function-coverage-fix.js : Because some odd issue for istanbul/nyc
    plugins.push.apply(plugins, ["./fix-coverage/arrow-function-coverage-fix.js", "babel-plugin-istanbul"]);
    break;

  case 'production':
    presets.push.apply(presets, ['minify']);
    break;
}

// default preset
presets.push.apply(presets, ["@babel/preset-env"]);

module.exports = {
  presets: presets,
  plugins: plugins,
  ignore: ignore,
  comments: comments,
};

Command to run production build

npm run prepare

Actual Output

TypeError: Cannot read property 'isPure' of null
    at Object.checkPath (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\path\lib\virtual-types.js:120:23)
    at NodePath.(anonymous function) [as isPure] (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\path\index.js:226:24)
    at isPureAndUndefined (D:\workspaceNodeJs\torrent-files-library\node_modules\babel-plugin-transform-remove-undefined\lib\index.js:21:13)
    at PluginPass.VariableDeclaration (D:\workspaceNodeJs\torrent-files-library\node_modules\babel-plugin-transform-remove-undefined\lib\index.js:216:21)
    at newFn (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\visitors.js:223:21)
    at NodePath._call (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\path\context.js:64:19)
    at NodePath.call (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\path\context.js:38:17)
    at NodePath.visit (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\path\context.js:99:12)
    at TraversalContext.visitQueue (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\context.js:139:18)
    at TraversalContext.visitMultiple (D:\workspaceNodeJs\torrent-files-library\node_modules\@babel\traverse\lib\context.js:93:17)

Thanks for your help.

bug needs info

Most helpful comment

Here's a workaround, disable removeUndefined:

['minify', { removeUndefined: false }]

All 8 comments

@jy95 Thanks for opening the issue. I am also facing the problem

Here's a workaround, disable removeUndefined:

['minify', { removeUndefined: false }]

thanks, seems to work like this :

presets.push.apply(presets, [['minify', { removeUndefined: false }]] );

Just wonder why this thing is set by default to true if it causes problems in ES modules ..

in my case

['minify', { removeUndefined: false, simplify: false }]

I've been able to narrow down to the line of code that causes the error message, an arrow function returning false seems to be the culprit. Made some other tests

const foo = () => false; // TypeError: Cannot read property 'isPure' of null
const bar = () => null; // TypeError: Cannot read property 'isPure' of null
const baz = () => undefined; // okay!

I'm not able to reproduce this.

const foo = () => false;
const bar = () => null;
const baz = () => undefined;

works as intended. Can someone here provide code that reproduces this error?

Try this one:

const someFunc = () => {
    let someVar; // <- this triggers it
}

Unrelated, but a nice discovery, also with minify:

let someVar; // "traverse.clearCache is not a function"

Both happen on https://babeljs.io/repl using its minify option checkbox.

I'm not able to reproduce this.

const foo = () => false;
const bar = () => null;
const baz = () => undefined;

works as intended. Can someone here provide code that reproduces this error?

https://babeljs.io/repl#?babili=true&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=BQMwrgdgxgLglgewsAlAAgN4Cg27QNwEMAnNGBMKACwGUYSYAJQiAEwBsBTYgGhzwHlKVALIJ8nZmy69-A3EOoAFBHAgwA3FjloA9LrQB5COwCeaCJ06traEAlKKqaThPUBnNEjTViCALacAHQ6cCBowMAA7mqsCFFBvgGcaAA-qRaE-HAA5oTkxEFg7twAgjmc6kH--dTAAEQAwsRwhjT1KCg6AgBkPWj1SE7u9MQw9WhqaHFQYIFVM3OVMACiXPMw6NjdeE50DFIc3GgAvHaQsIjIWzvyegbGZhZWrGQIaFQsR2juajlcAFonD5CCV3Ld5E4VGoYKcXG4YEEnJx3EEuBAcjBnCccWgAIxoAD88OWSIo1BRAG0AAwAXUS7DgywAmmgAFwWMDsdhaO64AC-WghTjEEkOMjh4Gg8CQwFcyxufPkRFIliiABVyVRoeohUqBPojCZzJZbOQPl8uD8_oDgVBQSiIQIwhF5VVkaj0ZjnABCXF4xX6u5Q1TqOEQLk87RBu7ETgwMDECC8mP86Mxw0AdRSSCepte5psIEIXJgSjjCLQUSolR-UD83L-aDAAAcnXg1ZrhDrYWc3YiPTT6VBGSyU0GXcBO1qe2gAHxvbuhzaYdt3ftBFsV5YAEU4xdLqHH-rTMcXymX4c4Gpny-PAkF6buiw2QUIrFYKwRABk4CNKtwDTDKM4w8OetAgeK3BgdgZ4tqCvwSByxbsCUEL8igep8i-pLvp-P5_jAAHEEBWr-OInD1GBIoUVBvCrnBCFwEhdiEKhnDoZhT5oGmGFHkAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=es2017%2Cbabili&prettier=false&targets=&version=7.5.5&externalPlugins=

Was this page helpful?
0 / 5 - 0 ratings