Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope Hoisting bug with libphonenumber-js #2284

Closed
acourdavault opened this issue Nov 15, 2018 · 2 comments · Fixed by #2491
Closed

Scope Hoisting bug with libphonenumber-js #2284

acourdavault opened this issue Nov 15, 2018 · 2 comments · Fixed by #2491

Comments

@acourdavault
Copy link

acourdavault commented Nov 15, 2018

🐛 bug report

I could not build a code using libphonenumber-js library, which works well without --experimental-scope-hoisting.

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

I have NO configuration at all, only CLI, see below

{
  "name": "components",
  "version": "1.0.0",
  "description": "components for stel app webpages",
  "main": "none",
  "devDependencies": {
    "cssnano": "^4.0.3",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "reactify": "^1.1.1"
  },
  "scripts": {
    "prebuild": "npm i -g parcel && npm i",
    "bundlePList": "parcel build -o patientlist.js -d ../../asset/components/ --no-source-maps --no-cache ./patientlist.js",
    "bundleGAtes": "parcel build -o gates.js -d ../../asset/components/ --no-source-maps --no-cache ./gates.js",
    "bundlePDetails": "parcel build -o patientdetails.js -d ../../asset/components/ --no-source-maps ./patientdetails.js",
    "bundle": "npm run bundlePDetails && npm run bundlePList && parcel build -o profile.js -d ../../asset/components/ --no-source-maps --no-cache ./profile.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "aesjs": "^1.0.0",
    "babel-polyfill": "^6.26.0",
    "chart.js": "^2.7.2",
    "crypto-js": "^3.1.9-1",
    "downloadjs": "^1.4.7",
    "formik": "^0.11.11",
    "isomorphic-fetch": "^2.2.1",
    "libphonenumber-js": "^1.2.15",
    "moment": "^2.22.2",
    "moment-timezone": "^0.5.21",
    "pako": "^1.0.6",
    "postcss-modules": "^1.1.0",
    "react-chartjs-2": "^2.7.4",
    "react-datepicker": "^1.7.0",
    "react-table": "^6.8.6",
    "react-virtualized-select": "^3.1.3",
    "reactjs-popup": "^1.1.4",
    "yup": "^0.25.1"
  }
}

🤔 Expected Behavior

i expected the build to go through

😯 Current Behavior

cannot build

PS D:\wc\stel\stel_dev\stel-django\stel\stelapp\components> parcel build -o .\patientSettingsPage.js -d ../../asset/components/ --no-source-maps  --experimental-scope-hoisting .\patientSettingsPage.js
×  node_modules\libphonenumber-js\es6\findPhoneNumbers.js does not export '$HkE9$export$searchPhoneNumbers'
    at replaceExportNode (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\parcel-bundler\src\scope-hoisting\concat.js:54:13)
    at ReferencedIdentifier (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\parcel-bundler\src\scope-hoisting\concat.js:317:20)
    at newFn (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\visitors.js:230:17)
    at NodePath._call (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\path\context.js:88:12)
    at TraversalContext.visitQueue (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\context.js:118:16)
    at TraversalContext.visitSingle (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\context.js:90:19)
    at TraversalContext.visit (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\context.js:146:19)
    at Function.traverse.node (C:\Users\adrie\AppData\Local\Yarn\Data\global\node_modules\@babel\traverse\lib\index.js:94:17)```

💁 Possible Solution

maybe related to a non ES6 compliant implementation of libphonenumber-js

🔦 Context

was trying to reduce the size of an existing page

💻 Code Sample

I used this import

import { parseNumber, AsYouType } from "libphonenumber-js";

🌍 Your Environment

windows 10, yarn install parcel bundler updated 1.10.3

@mischnic
Copy link
Member

Minimum example: (important bit: lib.js exports a function called x and reexports a functio with the same name)

// index.js
import { x } from "./lib.js";
// lib.js
export function x() {}

export { x as someFunction } from './lib2.js'
// lib2.js
export function x() {}
$ parcel build index.js --no-cache --experimental-scope-hoisting
🚨  lib2.js does not export '$oHGM$export$x'
    at replaceExportNode (.../node_modules/parcel-bundler/src/scope-hoisting/concat.js:54:13)
    at ReferencedIdentifier (.../node_modules/parcel-bundler/src/scope-hoisting/concat.js:317:20)
    at newFn (.../node_modules/@babel/traverse/lib/visitors.js:230:17)
    at NodePath._call (.../node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (.../node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (.../node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (.../node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (.../node_modules/@babel/traverse/lib/index.js:94:17)

@mischnic
Copy link
Member

mischnic commented Jan 1, 2019

This is closely related to babel/babel#9266, but parcel doesn't use babel's renaming facility so fixing it in babel doesn't help parcel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@DeMoorJasper @mischnic @acourdavault and others