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

Doesn't work with webpack #108

Closed
epicfaace opened this issue May 25, 2021 · 2 comments
Closed

Doesn't work with webpack #108

epicfaace opened this issue May 25, 2021 · 2 comments

Comments

@epicfaace
Copy link

Problem

I can't use whois when using webpack because of the shebang at the beginning of the compiled whois/index.js file.

image

I get the following error:

Entrypoint worker = worker.bundle.js
[0] ./src/worker.ts 116 bytes {0} [built]
    + 1 hidden module

ERROR in ./node_modules/whois/index.js 1:0
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> #!/usr/bin/env node
| 
| // Generated by CoffeeScript 2.5.1
 @ ./src/worker.ts 3:12-28

This is a similar issue to webpack/webpack#2168

Solution

The solution would be to remove the shebang from index.js and create a separate entry point, bin.js, which has the shebang and would be used for the CLI. See this commit to see how another library with a similar problem, JSONStream, did it: dominictarr/JSONStream@debb492

Temporary workaround

A short-term workaround for our purposes was to install string-replace-loader and then add the following within our webpack config rules key:

{
    test: path.resolve(__dirname, 'node_modules/whois/index.js'),
    loader: 'string-replace-loader',
    options: {
      search: '#!/usr/bin/env node',
      replace: ''
    }
}
@hjr265 hjr265 closed this as completed in 40faccd May 26, 2021
@epicfaace
Copy link
Author

Woah thanks for the fix @hjr265 ! That's awesome 😁

@hjr265
Copy link
Member

hjr265 commented May 26, 2021

@epicfaace No problem. Sorry I couldn't leave a note here earlier. I published the change and immediately had to switch to something else.

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

No branches or pull requests

2 participants