Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this webpack warning safe to ignore?

I found a strange warning in webpack. While parsing process.env using babel-loader. A warning(TypeError: result.setExpression is not a function) occurred inwebpack/lib/Parser.js. I'm on a big project and want my core to be super solid. So is it safe to ignore this warning, since webpack explicitly catches it and comments 'ignore error'?

The warning(TypeError: result.setExpression is not a function) occurred here(webpack/lib/Parser.js https://github.com/webpack/webpack/blob/2361995a429794d372d61e3fb628dea3929e0ca4/lib/Parser.js#L1987)

evaluateExpression(expression) {
    try {
        const hook = this.hooks.evaluate.get(expression.type);
        if (hook !== undefined) {
            const result = hook.call(expression);
            if (result !== undefined) {
                if (result) {
                    result.setExpression(expression);
                }
                return result;
            }
        }
    } catch (e) {
        console.warn(e);
        // ignore error
    }
    return new BasicEvaluatedExpression()
        .setRange(expression.range)
        .setExpression(expression);
}

I printed this result, and found it to be

BasicEvaluatedExpression {
  type: 0,
  range: [ 945, 956 ],
  falsy: false,
  truthy: true,
  bool: null,
  number: null,
  regExp: null,
  string: null,
  quasis: null,
  array: null,
  items: null,
  options: null,
  prefix: null,
  postfix: null } 

I also printed the expression

{
  type: 'MemberExpression',
  start: 945,
  end: 956,
  loc: 
   SourceLocation {
     start: Position { line: 16, column: 13 },
     end: Position { line: 16, column: 24 } },
  range: [ 945, 956 ],
  object: 
   Node {
     type: 'Identifier',
     start: 945,
     end: 952,
     loc: SourceLocation { start: [Object], end: [Object] },
     range: [ 945, 952 ],
     name: 'process' },
  property: 
   Node {
     type: 'Identifier',
     start: 953,
     end: 956,
     loc: SourceLocation { start: [Object], end: [Object] },
     range: [ 953, 956 ],
     name: 'env' },
  computed: false }

The process.env came from something like var isProd = process.env && process.env.NODE_ENV === 'production';

Background:

The complete warning message:

TypeError: result.setExpression is not a function
    at Parser.evaluateExpression (node_modules/webpack/lib/Parser.js:1991:14)
    at hooks.evaluate.for.tap.expr (node_modules/webpack/lib/Parser.js:368:17)
    at SyncBailHook.eval [as call] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
    at Parser.evaluateExpression (node_modules/webpack/lib/Parser.js:1984:25)
    at parser.hooks.statementIf.tap.statement (node_modules/webpack/lib/ConstPlugin.js:122:28)
    at SyncBailHook.eval [as call] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
    at Parser.walkIfStatement (node_modules/webpack/lib/Parser.js:1011:41)
    at Parser.walkStatement (node_modules/webpack/lib/Parser.js:961:10)
    at Parser.walkStatements (node_modules/webpack/lib/Parser.js:864:9)
    at Parser.walkBlockStatement (node_modules/webpack/lib/Parser.js:996:8)
    at Parser.walkStatement (node_modules/webpack/lib/Parser.js:931:10)
    at inScope (node_modules/webpack/lib/Parser.js:1603:10)
    at Parser.inScope (node_modules/webpack/lib/Parser.js:1910:3)
    at Parser.walkFunctionExpression (node_modules/webpack/lib/Parser.js:1596:8)
    at Parser.walkExpression (node_modules/webpack/lib/Parser.js:1509:10)
    at Parser.walkAssignmentExpression (node_modules/webpack/lib/Parser.js:1694:8)
    at Parser.walkExpression (node_modules/webpack/lib/Parser.js:1491:10)
    at Parser.walkExpressionStatement (node_modules/webpack/lib/Parser.js:1000:8)
    at Parser.walkStatement (node_modules/webpack/lib/Parser.js:946:10)
    at Parser.walkStatements (node_modules/webpack/lib/Parser.js:864:9)
    at Parser.walkBlockStatement (node_modules/webpack/lib/Parser.js:996:8)
    at Parser.walkStatement (node_modules/webpack/lib/Parser.js:931:10)
    at inScope (node_modules/webpack/lib/Parser.js:1792:10)
    at Parser.inScope (node_modules/webpack/lib/Parser.js:1910:3)
    at Parser._walkIIFE (node_modules/webpack/lib/Parser.js:1780:8)
    at Parser.walkCallExpression (node_modules/webpack/lib/Parser.js:1817:9)
    at Parser.walkExpression (node_modules/webpack/lib/Parser.js:1500:10)
    at Parser.walkVariableDeclaration (node_modules/webpack/lib/Parser.js:1381:32)
    at Parser.walkStatement (node_modules/webpack/lib/Parser.js:979:10)
    at Parser.walkStatements (node_modules/webpack/lib/Parser.js:864:9)
    at Parser.parse (node_modules/webpack/lib/Parser.js:2127:9)
    at doBuild.err (node_modules/webpack/lib/NormalModule.js:446:32)
    at runLoaders (node_modules/webpack/lib/NormalModule.js:327:12)
    at node_modules/loader-runner/lib/LoaderRunner.js:370:3
    at iterateNormalLoaders (node_modules/loader-runner/lib/LoaderRunner.js:211:10)
    at iterateNormalLoaders (node_modules/loader-runner/lib/LoaderRunner.js:218:10)

My babel configs are:

"webpack": "4.25.1",
"babel-core": "6.26.3",
"babel-eslint": "8.2.6",
"babel-loader": "7.1.5",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.7.0",
"babel-preset-react": "6.24.1",
"babel-register": "6.26.0",


const babelCoreConfig = {
    babelrc: false,
    presets: [
       'babel-preset-env',
       'babel-preset-react'
    ],
    plugins: [
       'babel-plugin-transform-class-properties',
        ['babel-plugin-transform-runtime', {
            helpers: true,
            polyfill: false,
            regenerator: false,
        }],
       'babel-plugin-transform-object-rest-spread'
    ]
};
like image 260
jchnxu Avatar asked Nov 08 '18 10:11

jchnxu


1 Answers

I have faced this very same issue and struggled for about half a day in solving it. I was getting this warning at module.hot expression. I was using react-hot-loader.

I have removed the option --hot in webpack-dev-server --hot --config ./webpack.dev.config.js --mode development and added the webpackHotModuleReplacementPlugin in webpack config. This fixed the issue.

Where is this process.env being used? If its in webpack config and if your webpack config is a simple JS object export, it would be undefined.

If its in a file, try logging it and check if its undefined.

like image 166
KartheekJ Avatar answered Oct 05 '22 23:10

KartheekJ