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

Invalid arg type error with --input-dir / --output-dir options #74

Closed
laurentpayot opened this issue Sep 2, 2021 · 8 comments
Closed
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@laurentpayot
Copy link
Contributor

html-minifier-terser version: 6.0.1
OS: Ubuntu 21.04

On node 14.0.0 and above if I use the following command:

npx --package node@14.0.0 -- html-minifier-terser --file-ext html --input-dir src --output-dir dist

I get:

internal/fs/utils.js:656
    throw new ERR_INVALID_ARG_TYPE(
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Promise
    at Object.writeFile (fs.js:1356:5)
    at /home/laurent/projects/myproject/node_modules/html-minifier-terser/cli.js:245:8
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

On node 13.14.0 the following command generates no error:

npx --package node@13.14.0 -- html-minifier-terser --file-ext html --input-dir src --output-dir dist

but the content of the minified html file is:

 [object Promise]

Everything was working fine with html-minifier-terser v5.1.1

@laurentpayot laurentpayot changed the title CLI node error Invalid arg type error Sep 2, 2021
@DanielRuf
Copy link
Contributor

Can you provide a PR and test it with different test cases? That would be great.

See also 4d03536

@DanielRuf DanielRuf added bug Something isn't working help wanted Extra attention is needed labels Sep 2, 2021
@laurentpayot
Copy link
Contributor Author

@DanielRuf I just found out that the simpler command line html-minifier-terser src/index.html -o dist/index.html is working.
The culprit must be the --input-dir/--output-dir options.

@laurentpayot laurentpayot changed the title Invalid arg type error Invalid arg type error with --input-dir / --output-dir options Sep 2, 2021
@DanielRuf
Copy link
Contributor

DanielRuf commented Sep 2, 2021

html-minifier-terser/cli.js:245:8

Yes, see this line where no async / await is used:

https://github.com/terser/html-minifier-terser/blob/v6.0.1/cli.js#L240

And compare it to this:

https://github.com/terser/html-minifier-terser/blob/v6.0.1/cli.js#L281

@sibiraj-s
Copy link
Collaborator

We definitely need tests for this cli file.

@DanielRuf
Copy link
Contributor

We definitely need tests for this cli file.

Definitely, see also #33

Personally I am not investing much time in opensource anymore due to personal reasons so if anyone wants to help that would be great.

@laurentpayot
Copy link
Contributor Author

Created PR #75

@DanielRuf
Copy link
Contributor

html-minifier-terser v6.0.2 has been released and the issue in the CLI should be fixed now.

Thanks for reporting the issue and thanks for the PR to fix this.
If this issue is still not resolved, please let me know and I will reopen this issue.

Not sure what the best solution is to test the CLI.

@sibiraj-s
Copy link
Collaborator

Not sure what the best solution is to test the CLI.

To start with, we don't need to test the entire cli, we can split the processing part into separate modules/files and test them alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants