parcel-bundler / parcel

The zero configuration build tool for the web. šŸ“¦šŸš€
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

@parcel/transformer-js: Mutating process.env is not supported #7054

Closed zababurinsv closed 3 years ago

zababurinsv commented 3 years ago

šŸ› bug report

šŸŽ› Configuration (.babelrc, package.json, cli command)

.babelrc

not this file

package.json

 "dependencies": {
    "babel-runtime": "^6.26.0",
    "@pinata/sdk": "^1.1.23",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "enqueue": "^1.0.2",
    "express": "^4.17.1",
    "express-enqueue": "^1.0.0",
    "express-formidable": "^1.2.0",
    "ipfs": "0.59.1",
    "ipfs-pubsub-1on1": "^0.0.7",
    "ipld": "^0.30.2",
    "ipns": "^0.15.0",
    "leveldown": "^6.1.0",
    "multiformats": "^9.4.8",
    "orbit-db-access-controllers": "^0.3.2",
    "orbit-db-cache": "^0.4.0",
    "orbit-db-counterstore": "^1.12.0",
    "orbit-db-docstore": "^1.12.0",
    "orbit-db-eventstore": "^1.12.0",
    "orbit-db-feedstore": "^1.12.0",
    "orbit-db-identity-provider": "^0.4.0",
    "orbit-db-io": "^1.0.1",
    "orbit-db-keystore": "^1.0.0",
    "orbit-db-kvstore": "^1.12.0",
    "orbit-db-pubsub": "^0.6.0",
    "orbit-db-storage-adapter": "^0.6.0",
    "orbit-db-store": "^4.2.0",
    "peer-id": "^0.15.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "simple-peer": "^9.11.0",
    "z-events": "^0.2.4"
  },
  "devDependencies": {
    "@babel/core": "^7.15.8",
    "@babel/plugin-proposal-class-properties": "^7.14.5",
    "@babel/plugin-proposal-decorators": "^7.15.8",
    "@babel/plugin-proposal-do-expressions": "^7.14.5",
    "@babel/plugin-proposal-export-default-from": "^7.14.5",
    "@babel/plugin-proposal-export-namespace-from": "^7.14.5",
    "@babel/plugin-proposal-function-bind": "^7.14.5",
    "@babel/plugin-proposal-function-sent": "^7.14.5",
    "@babel/plugin-proposal-json-strings": "^7.14.5",
    "@babel/plugin-proposal-logical-assignment-operators": "^7.14.5",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
    "@babel/plugin-proposal-numeric-separator": "^7.14.5",
    "@babel/plugin-proposal-optional-chaining": "^7.14.5",
    "@babel/plugin-proposal-pipeline-operator": "^7.15.0",
    "@babel/plugin-proposal-throw-expressions": "^7.14.5",
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "@babel/plugin-syntax-import-meta": "^7.10.4",
    "@babel/plugin-transform-react-constant-elements": "^7.14.5",
    "@babel/plugin-transform-react-inline-elements": "^7.14.5",
    "@babel/plugin-transform-typescript": "^7.15.8",
    "@babel/preset-env": "^7.15.8",
    "@babel/preset-flow": "^7.14.5",
    "@babel/preset-react": "^7.14.5",
    "@babel/register": "^7.15.3",
    "@parcel/transformer-js": "2.0.0-nightly.335",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^10.1.0",
    "babel-jest": "^27.2.5",
    "babel-loader": "^8.2.2",
    "babel-plugin-dev-expression": "^0.2.2",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "dotenv": "^10.0.0",
    "eslint": "^8.0.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-airbnb-typescript": "^14.0.1",
    "eslint-config-erb": "^4.0.3",
    "eslint-config-prettier": "^8.3.0",
    "eslint-formatter-pretty": "^4.1.0",
    "eslint-import-resolver-webpack": "^0.13.1",
    "eslint-plugin-compat": "^3.13.0",
    "eslint-plugin-flowtype": "^6.1.0",
    "eslint-plugin-import": "^2.24.2",
    "eslint-plugin-jest": "^25.0.3",
    "eslint-plugin-jsx-a11y": "6.4.1",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-promise": "^5.1.0",
    "eslint-plugin-react": "^7.26.1",
    "eslint-plugin-testcafe": "^0.2.1",
    "nodemon": "^2.0.13",
    "npm-run-all": "^4.1.5",
    "parcel": "2.0.0-rc.0",
    "parcel-reporter-static-files-copy": "^1.3.0",
    "style-loader": "^3.3.0",
    "stylelint": "^13.13.1",
    "stylelint-config-prettier": "^8.0.2",
    "stylelint-config-standard": "^22.0.0"
  },

cli command

    "dev:initiator": "parcel $npm_package_config_path_initiator --port $npm_package_config_port_initiator --dist-dir ./docs",
    "dev:dialer": "parcel $npm_package_config_path_dialer --port $npm_package_config_port_dialer --dist-dir ./docs",
    "build:initiator": "parcel build $npm_package_config_path_initiator --dist-dir ./docs",
    "build:dialer": "parcel build $npm_package_config_path_dialer --dist-dir ./docs",
    "kill:dialer": "kill $(lsof -t -i:$npm_package_config_dialer)",
    "kill:initiator": "kill $(lsof -t -i:$npm_package_config_initiator)",

šŸ¤” Expected Behavior

Error

@parcel/transformer-js: Mutating process.env is not supported

  /home/zb/Desktop/webrtc/node_modules/@pinata/sdk/lib/pinata-sdk.js:205:1
    204 |   \********************************************/
  > 205 | /*! no static exports found */
  >     | ^
    206 | /***/ (function(module, exports) {
    207 | 

@parcel/transformer-js: Mutating process.env is not supported

  /home/zb/Desktop/webrtc/node_modules/@pinata/sdk/lib/pinata-sdk.js:209:1
    208 | module.exports = defer;
  > 209 | 
  >     | ^
    210 | /**
    211 |  * Runs provided function on next iteration of the event loop

But server is working

šŸ˜Æ Current Behavior

How can I remove the error?

devongovett commented 3 years ago

@pinata/sdk contains the following function:

function save(namespaces) {
    if (namespaces) {
        process.env.DEBUG = namespaces;
    } else {
        // If you set a process.env field to null or undefined, it gets cast to the
        // string 'null' or 'undefined'. Just delete instead.
        delete process.env.DEBUG;
    }
}

This mutates process.env, which is not supported by Parcel because it would break inlining environment variables.

betabandido commented 2 years ago

@devongovett Is there any workaround for this?

We are hitting this issue as a chain of dependencies results into including the package https://www.npmjs.com/package/debug, which contains the same code listed on your reply.

This is currently blocking us from using Parcel, which we were hoping to use. And, I can imagine this issue might affect many other people, as there are almost 42k packages depending on debug.

Of course, it might be the case there's not a real reason to include the debug package to start with. But, we would need to chase quite a few package maintainers and convince them to change their dependencies. That's unlikely to happen (at least in the short-term).

devongovett commented 2 years ago

Are you bundling for a browser target or node? It looks like there is a browser version that doesn't do that. The browser field should automatically be picked up when building for a browser target. https://github.com/visionmedia/debug/blob/master/package.json#L55

betabandido commented 2 years ago

I tried your suggestion and I can confirm, in my case, the issue went away after I built the app for a browser target. Thanks!

chriscanossi commented 2 years ago

@devongovett , I'm working in a monorepo and bundling for a browser, but I'm seeing the following warning. I've found this which also outlines a similar issue. What can I try to resolve this issue?

image

suleymangezsat commented 2 years ago

@chriscanossi I'm facing the same issue.. Did you find any solution / workaround ?

chriscanossi commented 2 years ago

@chriscanossi I'm facing the same issue.. Did you find any solution / workaround ?

@suleymangezsat, Unfortunately, no. Still seeing the verbose warning. It would nice to have an option to disable it.