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

3.x using Object.defineProperty with process.env failed #2998

Closed
pmq20 opened this issue Sep 22, 2015 · 3 comments
Closed

3.x using Object.defineProperty with process.env failed #2998

pmq20 opened this issue Sep 22, 2015 · 3 comments
Labels
process Issues and PRs related to the process subsystem.

Comments

@pmq20
Copy link
Contributor

pmq20 commented Sep 22, 2015

Originally discovered by @popomore .

In io.js 3.x, Using Object.defineProperty with process.env failed in that, process.env will not actually store the value into the environment variables but on the object itself. This also results in subsequent delete operation failed.

image

Other objects work fine.

image

pmq20 added a commit to pmq20/node that referenced this issue Sep 22, 2015
@brendanashworth brendanashworth added the process Issues and PRs related to the process subsystem. label Sep 22, 2015
@evanlucas
Copy link
Contributor

Closing as we are not planning to do another io.js release. (#3465)

@gucong3000
Copy link

setter is not work for me.

Object.defineProperty(process.env, 'SHELL', {
	get: function () {
		console.log('get');
		return '';
	},
	set: function (value) {
		console.log('set');
	},
	enumerable: true,
});
console.log(process.env.SHELL);
process.env.SHELL = 'test';
E:\work\git-bash-shell (os -> origin) ([email protected])
$ node -v
v9.2.0

E:\work\git-bash-shell (os -> origin) ([email protected])
$ node test.js
get

@gucong3000
Copy link

I found the right way.

Object.defineProperties(
	Object.getPrototypeOf(process.env),
	env
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants