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

MemberExpressions attempts to convert process.env.hasOwnProperty to a node #1440

Closed
EricRabil opened this issue May 25, 2018 · 7 comments · Fixed by #1953
Closed

MemberExpressions attempts to convert process.env.hasOwnProperty to a node #1440

EricRabil opened this issue May 25, 2018 · 7 comments · Fixed by #1953

Comments

@EricRabil
Copy link

EricRabil commented May 25, 2018

🐛 bug report

At /src/visitors/globals.js:26, Parcel is recognizing DotEnv's call to process.env.hasOwnProperty(...) and is attempting to convert it to a node, causing the babel converter to throw an exception.

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

.babelrc

{
    "presets": [
        ["env", {
            "targets": {
                "browsers": ["last 1 Chrome version"]
            }
        }]
    ]
}

package.json

{
  "name": "StormStarter",
  "version": "1.0.0",
  "main": "out/index.js",
  "repository": "https://github.com/EricRabil/StormStarter.git",
  "author": "EricRabil <ericjrabil@gmail.com>",
  "license": "MIT",
  "dependencies": {
    "babel-polyfill": "^6.26.0",
    "bcrypt": "^2.0.1",
    "biguint-format": "^1.0.0",
    "cookie-parser": "^1.4.3",
    "express": "^4.16.3",
    "express-session": "^1.15.6",
    "flake-idgen": "^1.1.0",
    "fs-extra": "^6.0.0",
    "keymirror": "^0.1.1",
    "mongodb": "^3.0.7",
    "nobi": "^0.0.1",
    "parcel": "^1.8.1",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "passport-unique-token": "^0.1.4",
    "pug": "^2.0.3",
    "superagent": "^3.8.3",
    "typeorm": "^0.2.5",
    "uws": "^10.148.0",
    "vue": "^2.5.16",
    "vue-hot-reload-api": "^2.3.0",
    "vue-router": "^3.0.1",
    "webpack": "^4.7.0",
    "winston": "2.4.0"
  },
  "devDependencies": {
    "@vue/component-compiler-utils": "^1.3.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "node-sass": "^4.9.0",
    "typescript": "^2.8.3",
    "vue-template-compiler": "^2.5.16"
  }
}

cli

parcel watch index.html -d ../../out/frontend

🤔 Expected Behavior

It should be able to compile

😯 Current Behavior

It throws the above error due to DotEnv

/Users/ericrabil/eric.git/StormStarter/node_modules/dotenv/lib/main.js: don't know how to turn this value into a node
    at Object.valueToNode (/Users/ericrabil/.config/yarn/global/node_modules/babel-types/lib/converters.js:349:9)
    at MemberExpression (/Users/ericrabil/.config/yarn/global/node_modules/parcel-bundler/src/visitors/globals.js:26:25)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:149:9)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:186:9)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:186:9)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:186:9)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:183:11)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:186:9)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:183:11)
    at c (/Users/ericrabil/.config/yarn/global/node_modules/babylon-walk/lib/index.js:186:9)

💁 Possible Solution

In /src/visitors/globals.js at the MemberExpressions definition, check whether the inline access to process.env is a function call, and if so, do not attempt to coerce it to a node.

🔦 Context

The issue affects me by preventing the build process from completing.

I am spawning a parcel instance through child_process however the error occurs when running it from a standard CLI. I am compiling a TypeScript/Vue project and redirecting it to another directory.

💻 Code Sample

https://github.com/EricRabil/StormStarter

🌍 Your Environment

Software Version(s)
Parcel 1.7.1, 1.8.1
Node 10.2.1, 8.9.0
npm/Yarn 1.7.0
Operating System macOS 10.13.4
@Ronnie1734
Copy link

Had the same error in this project.

Tag-it/image-tagger@3f9490e

@EricRabil
Copy link
Author

@Ronnie1734 does yours still repro / have you found a fix?

@EricRabil
Copy link
Author

Anyone?

@TrueCarry
Copy link

@EricRabil Hello. Just tried to use parcel and it can't load dotenv. To repro you need just two lines of code:

import dotenv from 'dotenv'
dotenv.config()

@jchu4483
Copy link

Getting the same error when trying to use dotenv in my project when running parcel too.

@Strajk
Copy link

Strajk commented Aug 1, 2018

@TrueCarry @jchu4483

Having same issue, have you been lucky solving it pls?


EDIT: Not a fix, but quick workaround is to use dotenv v4.0.0 - works well
https://github.com/motdotla/dotenv/releases/tag/v4.0.0

@manthis
Copy link

manthis commented Aug 21, 2018

Same here, impossible to use dotenv with parcel. Any update on that subject?

DeMoorJasper pushed a commit that referenced this issue Aug 28, 2018
This fixes #1440. Package "dotenv" does something like "process.env.hasOwnProperty( ... )".
Parcel expects a value property lookup on process.env, not a function call. So valueToNode fails if it was called with a function like "hasOwnProperty".
devongovett pushed a commit that referenced this issue Oct 15, 2018
This fixes #1440. Package "dotenv" does something like "process.env.hasOwnProperty( ... )".
Parcel expects a value property lookup on process.env, not a function call. So valueToNode fails if it was called with a function like "hasOwnProperty".
devongovett pushed a commit that referenced this issue Oct 15, 2018
This fixes #1440. Package "dotenv" does something like "process.env.hasOwnProperty( ... )".
Parcel expects a value property lookup on process.env, not a function call. So valueToNode fails if it was called with a function like "hasOwnProperty".
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.

7 participants