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

Fixed import errors on modules with shebang declarations #179

Merged
merged 2 commits into from
Dec 18, 2021

Conversation

breautek
Copy link
Contributor

@breautek breautek commented Mar 31, 2020

Fixes #178

I feel like the issue should really be fixed in NodeJS, but this PR provides a workaround for the time being.

I've isolated the tests and the fix into two different commits, so that the fix commit could be reverted at a later date easily, should NodeJS provides a fix in the future.

This fixes the issue by removing the shebang declaration during the import via a regex that scans the first line of the module source. I believe this is a safe workaround because during a test environment, we don't need shebang declarations.

I've ran npm test to ensure all other tests passed.

Additionally I've tested my changes locally on https://github.com/apache/cordova-android who is exhibiting this issue on NodeJS 12.16.0+

Do note that this is not an issue on NodeJS 12.15 or earlier.

As of NodeJS 12.16.0, importing modules with shebang declarations failed.
This commit checks the first line for shebang declarations and removes them
before trying to load the module.
@mbwhite
Copy link

mbwhite commented Apr 2, 2020

I agree that this seemed to be triggered by Node.js - do you know what the change in node that triggered this?

@rensbaardman
Copy link
Contributor

I agree that this seemed to be triggered by Node.js - do you know what the change in node that triggered this?

See the changes mentioned in the original issue: previously, Node would strip out the shebang before passing it on. Now it doesn't anymore.

@fbilbie
Copy link

fbilbie commented Jul 14, 2020

Any reason why this PR is not merged? This issue is a deal breaker when using this package on node versions >= 12.16

@mbwhite
Copy link

mbwhite commented Sep 2, 2020

Same question as @fbilbie fully appreciate that there is an argument that the node.js change shouldn't have occurred.
I noticed there was a v5 of rewire.. can this be merged?

@richmar10
Copy link

Hi, This would help us out with an issue as well. Can this be merged? Thanks!

@jhnns jhnns merged commit 54440b6 into jhnns:master Dec 18, 2021
@breautek breautek deleted the shebang-fix branch December 18, 2021 23:46
@jhnns
Copy link
Owner

jhnns commented Dec 19, 2021

Thank you 🙏

Published as v6.0.0 🚀

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

Successfully merging this pull request may close these issues.

Node shebang line results in error since Node.js 12.16.0
6 participants