Skip to content

Exporting constants breaks minification #820

@bashlyss

Description

@bashlyss

Input Code

 const ONE_SECOND = 1000;
 const ESCAPE_KEY = 27;
 const LEFT_ARROW_KEY = 37;
 const RIGHT_ARROW_KEY = 39;
  
 export {
   ONE_SECOND,
   ESCAPE_KEY,
   LEFT_ARROW_KEY,
   RIGHT_ARROW_KEY,
 };

Actual Output

ERROR in ./zanbato/frontend/utils/Constants.js
    Module build failed: TypeError: /utils/Constants.js: Property local of ExportSpecifier expected node to be of a type ["Identifier"] but instead got "NumericLiteral"
        at Object.validate (node_modules/babel-types/lib/definitions/index.js:109:13)
        at Object.validate (/node_modules/babel-types/lib/index.js:505:9)
        at NodePath._replaceWith (node_modules/babel-traverse/lib/path/replacement.js:176:7)
        at NodePath.replaceWith (node_modules/babel-traverse/lib/path/replacement.js:160:8)
        at PluginPass.Expression (node_modules/babel-plugin-minify-constant-folding/lib/index.js:199:16)
        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)
        at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:105:12)
        ...
        at transpile (node_modules/babel-loader/lib/index.js:50:20)
        at Object.module.exports (node_modules/babel-loader/lib/index.js:173:20)

Expected Output

I should be able to export my constants without compilation issues

Details

If there is another way I should be defining this, or a way I can use the preset and omit the constant folding, that would work as an interim solution.

EDIT: Removed some of the verbosity of the backtrace for easier reading

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions