CLI broken since version 8
Closed this issue · 5 comments
sgtlambda commented
Happens both when installed locally, as well as when using npx
.
➜ min npx minify test.js
Need to install the following packages:
minify
Ok to proceed? (y)
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/sgtlambda/.npm/_npx/cfbbf1728dde0171/node_modules/minify/' is not supported resolving ES modules imported from /Users/sgtlambda/.npm/_npx/cfbbf1728dde0171/node_modules/minify/bin/minify.js
at new NodeError (node:internal/errors:370:5)
at finalizeResolution (node:internal/modules/esm/resolve:317:17)
at moduleResolve (node:internal/modules/esm/resolve:756:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:867:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at Loader.import (node:internal/modules/esm/loader:177:28)
at importModuleDynamically (node:internal/modules/esm/translators:116:35)
at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:30:14)
at uglifyFiles (file:///Users/sgtlambda/.npm/_npx/cfbbf1728dde0171/node_modules/minify/bin/minify.js:85:20) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///Users/sgtlambda/.npm/_npx/cfbbf1728dde0171/node_modules/minify/'
}
Replacing minify
with minify@7
in the command above makes it work.
coderaiser commented
Thank you! Landed in v8.0.1 🎉 . Is it works for you?
takayukioda commented
@coderaiser
v8.0.1
fixed directory importing error, but I got another error.
Let me know if you need any additional information.
% cat << EOT > hello.js
const hello = 'world';
for (let i = 0; i < hello.length; i++) {
console.log(hello[i]);
}
EOT
% npx minify@8.0.1 hello.js
TypeError: minify is not a function
at file:///Users/oda/.npm/_npx/b6c5618f6e40a9aa/node_modules/minify/bin/minify.js:86:43
at Array.map (<anonymous>)
at uglifyFiles (file:///Users/oda/.npm/_npx/b6c5618f6e40a9aa/node_modules/minify/bin/minify.js:86:29)
at async minify (file:///Users/oda/.npm/_npx/b6c5618f6e40a9aa/node_modules/minify/bin/minify.js:65:5)
% npx minify@8.0.0 hello.js
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/oda/.npm/_npx/921c00bef1f37306/node_modules/minify/' is not supported resolving ES modules imported from /Users/oda/.npm/_npx/921c00bef1f37306/node_modules/minify/bin/minify.js
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:412:17)
at moduleResolve (node:internal/modules/esm/resolve:932:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:1044:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at Loader.import (node:internal/modules/esm/loader:177:28)
at importModuleDynamically (node:internal/modules/esm/translators:115:35)
at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:30:14)
at uglifyFiles (file:///Users/oda/.npm/_npx/921c00bef1f37306/node_modules/minify/bin/minify.js:85:20) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///Users/oda/.npm/_npx/921c00bef1f37306/node_modules/minify/'
}
% npx minify@7 hello.js
const hello="world";for(let l=0;l<hello.length;l++)console.log(hello[l]);
takayukioda commented
It seems lib/minify.js
exports object with property default
.
When I directly edit bin/minify.js
as following code, it worked.
Not sure what's the best way to fix the code though.
async function uglifyFiles(files, options) {
const { default: minify } = await import('../lib/minify.js'); // destruct `default` and rename it to `minify`
const minifiers = files.map((file) => minify(file, options));
Promise.all(minifiers)
.then(logAll)
.catch(log.error);
}
BTW here's my environment
% node --version
v16.10.0
% npx --version
7.24.0
coderaiser commented
Thank you! Landed in v8.0.2 🎉 . Is it works for you?
takayukioda commented
@coderaiser thanks! it worked as expected 👍🏽
% cat << EOT > hello.js
const hello = 'world';
for (let i = 0; i < hello.length; i++) {
console.log(hello[i]);
}
EOT
% npx minify@8.0.2 hello.js
const hello="world";for(let l=0;l<hello.length;l++)console.log(hello[l]);