Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Breaking change if using in a js script #84

Closed
thomasthiebaud opened this issue Mar 14, 2017 · 10 comments · Fixed by #87
Closed

Breaking change if using in a js script #84

thomasthiebaud opened this issue Mar 14, 2017 · 10 comments · Fixed by #87

Comments

@thomasthiebaud
Copy link
Contributor

I was using cross-env with version 3.1.4 like this

const crossEnv = require('cross-env');
...
crossEnv(['node', 'bin/execute', ...argv._]);

I recently migrated to the latest version 3.2.3 and I had this error

TypeError: crossEnv is not a function

I finally found the error, I needed to change the import to

const crossEnv = require('cross-env').default;

It broke my build, so maybe more peoples are facing the same issue. Would it be possible to add some more documentation about it?

@kentcdodds
Copy link
Owner

Ah, yeah, it was never intended to be used like that. However, I'd be willing to accept a change to make it more ergonomic. You'd have to change this to module.exports = crossEnv. Should be pretty straightforward. If you'd like to do this, please also verify that you can still use the binary in the normal way.

Thanks!

@kentcdodds
Copy link
Owner

Note also that I do not consider it a breaking change as it was never intended to be used that way and it's not documented. So you don't need to worry about this requiring a major release or anything.

@kentcdodds
Copy link
Owner

We're going to go ahead and put this in the next major version. If you want to do this, please open a PR to the next branch 👍

@thomasthiebaud
Copy link
Contributor Author

Yes sure I can do it

@thomasthiebaud
Copy link
Contributor Author

If I only replace

export default crossEnv

by

module.exports = crossEnv

I have an linter error (no default export). I can either :

  • disable the rule (globally or on this line only)
  • use both exports (it works, I didn't known before testing. I added a test for this case)

@kentcdodds
Copy link
Owner

Ah yes, just disable it with // eslint-disable-next-line

@thomasthiebaud
Copy link
Contributor Author

Ok so I will modify my PR

@kentcdodds
Copy link
Owner

This will be released as soon as we merge the next branch (hopefully soon)

@kentcdodds
Copy link
Owner

Could you please try out cross-env@beta and make sure this resolves your issue?

@thomasthiebaud
Copy link
Contributor Author

It solves my problem (version 4.0.0-beta.0)

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

Successfully merging a pull request may close this issue.

2 participants