Skip to content

babel lodash plugin and parcel tree shaking #1821

@zxol

Description

@zxol

🐛 bug report

lodash plugin for babel does not seem to work with parcel --experimental-scope-hoisting

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

{
    "name": "parcelbabel",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "build": "NODE_ENV=production && rm -rf ./dist && parcel build --experimental-scope-hoisting index.html"

    },
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "babel-plugin-lodash": "^3.3.4",
        "parcel-bundler": "^1.9.7"
    },
    "babel": {
        "plugins": ["lodash"]
    }
}

🤔 Expected Behavior

It should build properly.

😯 Current Behavior

Build errors out with the following error:

🚨  /home/andymac/devl/parcelbabel/index.js: Cannot read property 'constantViolations' of undefined
    at rename (/home/andymac/devl/parcelbabel/node_modules/parcel-bundler/src/scope-hoisting/renamer.js:9:33)
    at JSAsset.ImportDeclaration (/home/andymac/devl/parcelbabel/node_modules/parcel-bundler/src/scope-hoisting/hoist.js:327:7)
    at NodePath._call (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/home/andymac/devl/parcelbabel/node_modules/babel-traverse/lib/path/context.js:115:19)

💁 Possible Solution

Not sure. I know I could (and I have) refactored my code to use 'lodash-es' and import single functions. But I thought this bug report could be useful.

🔦 Context

💻 Code Sample

minimal code sample:
https://github.com/zxol/parcelbabel

🌍 Your Environment

Software Version(s)
Parcel 1.97
Node 8.11.3
npm/Yarn 5.5.1
Operating System ubuntu 16.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions