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

Terser returns error if folders, specified in --output parameter are not present in file system #962

Open
alexejibishvili opened this issue Mar 18, 2021 · 5 comments · May be fixed by #1530

Comments

@alexejibishvili
Copy link

Hello!

Can't exactly say its a bug or I'm missing something

Version: terser 5.6.1

I run a command:
npx terser wwwroot/build/js/admin.js --compress typeofs=false --mangle --comments "/^!/" --output wwwroot/dist/js/admin.min.js

Then I get an error:
Error: ENOENT: no such file or directory, open 'wwwroot/dist/js/admin.min.js'
at Object.openSync (fs.js:476:3)
at Object.writeFileSync (fs.js:1467:35)
at run_cli (C:\Users\Alex\source\repos\x\src\Web\node_modules\terser\dist\bundle.min.js:26901:16)
at run_cli (C:\Users\Alex\source\repos\x\src\Web\node_modules\terser\dist\bundle.min.js:26782:5) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'wwwroot/dist/js/admin.min.js'
}

Expected result: I expect to see minified file in --output wwwroot/dist/js/admin.min.js

If I have "dist" folder empty with no subfolders, I get the error.
If I create "js" folder inside "dist" folder, then minified file is create and I get no error.

Am I missing something or terser just does not create output folders by itself?

@jridgewell
Copy link
Collaborator

Seems like we could use mkdirp to recursively create the output directory. This needs to be done at

fs.writeFileSync(program.output, result.code);
.

@alistairtweedie
Copy link

Is there any appetite to work on this? 😕

@groovenectar
Copy link

I think it could be a nice option

@groovenectar
Copy link

Maybe not default behavior? I would definitely use it personally

@MohamedLamineAllal
Copy link

MohamedLamineAllal commented Nov 7, 2023

Every file processing tool does support this. It doesn't make sense to not support it.
And it should be part of the CLI only.

RyanZim added a commit to RyanZim/terser that referenced this issue May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants