question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on overwriting file with minified content

See original GitHub issue

I’d like to use this tool in my CD pipeline to overwrite a simple HTML file I have for a site. However, using the same input & output throws an error and does not succeed.

➜  start_page git:(master) ✗ npx minify static/index.html > static/index.html
npx: installed 25 in 2.483s
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(data)

    at AsyncFunction.module.exports [as html] (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/html.js:38:5)
    at onDataRead (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/minify.js:75:44)
    at optimize (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/minify.js:61:18)
    at async minify (/home/x/.npm/_npx/48208/lib/node_modules/minify/lib/minify.js:35:12)
    at async Promise.all (index 0) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: '',
  expected: true,
  operator: '=='
}

As this is the very last step in a deploy I really have no need to keep the original, unminified version around, so overwriting is ideal. As of now I have to write, remove the original, and then rename the minified version, which is a bit of an annoyance.

I’ll take a look myself, see if I can’t get something together to resolve this.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
code-forgercommented, Jul 16, 2021

This is actually an issue in Bash. using $ minify hello.js > hello.js Bash will first execute the file redirect, prepare hello.js for writing by wiping it. Then it will execute the left hand side, allowing minify to read the now empty hello.js

Short of adding a flag called something like --overwrite-source that minifies, then writes the files back over themselves this project cannot support this.

@coderaiser What are your thoughts? would you be interested in a PR to that effect?

0reactions
coderaisercommented, Jul 16, 2021

@code-forger yes, that’s amazing idea for a PR 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gulp js cssmin issue. Can't overwrite existing minified files
UPD: After removing the bootstrap-theme.min.css, the error is caused by another one. Conclusion: the task can't overwrite the existing min.css ...
Read more >
Avoiding Common Implementation Mistakes
The following scenarios represent some of the most common mistakes observed when implementing GPT. While such implementations may appear to ...
Read more >
CSS/JS Issues | Troubleshooting | LSCache for WordPress
Troubleshooting JavaScript, CSS, and other page optimization issues in the LiteSpeed Cache for WordPress Plugin.
Read more >
Ignoring Code - ESLint - Pluggable JavaScript Linter
You can configure ESLint to ignore certain files and directories while ... '!<relative/path/to/filename>'") to override ✖ 1 problem (0 errors, 1 warning).
Read more >
How to Overwrite a File in Python? (5 Best Methods with Code)
If the file contains any content, it will be completely overwritten by anything you write on the opened file. All the previous data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found