Closed DrLambs closed 5 years ago
FWIW I think this may be to do with this code which loads modules dynamically, presumably webpack would be picking them up if it weren't for them being in map??
// node.js
exports.FILES = [
"../lib/utils.js",
"../lib/ast.js",
"../lib/parse.js",
"../lib/transform.js",
"../lib/scope.js",
"../lib/output.js",
"../lib/compress.js",
"../lib/sourcemap.js",
"../lib/mozilla-ast.js",
"../lib/propmangle.js",
"../lib/minify.js",
"./exports.js",
].map(function(file) {
return require.resolve(file);
});
Not an issue with this project, please contact & consult with webpack instead.
@homerjam Yeah, I'm guessing this would all work if it just exported an array of require statements...
I feel like this is actually an issue that should be solved here. There are many different packaging and transpilation tools that all struggle with dynamic imports/requires.
In some cases it's necessary to do a dynamic import, but in this case it is not, so it should be relatively easy to fix.
I'm willing to put in a PR, if that helps?
Any progress here? With this issue I can't webpack email-templates
Any news in this issue?
I solved it by adding all the packages that use uglify or any other package that can't parsed by webpack to the externals
. See this issue.
@OBrown92 If someone does use next.js I solved it like the below:
const path = require('path');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
module.exports = withBundleAnalyzer({
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.module.rules.push({
test: path.resolve(__dirname, 'node_modules/uglify-js/tools/node.js'),
loader: 'null-loader',
});
// Important: return the modified config
return config;
},
...
}
@alexlamsl I disagree with your comment that it is not an issue with this project. Failing to build with all the popular build tools is a problem.
I was trying to use uglify-js in Deno with esm.sh, and this also causes the same issue: (error code for Googlers with this problem)
error: Uncaught NotFound: The system cannot find the path specified. (os error 3): readfile '../lib/utils.js'
at Object.readFileSync (ext:deno_fs/30_fs.js:704:14)
at Object.readFileSync (ext:deno_node/_fs/_fs_readFile.ts:43:23)
at https://esm.sh/v126/uglify-js@3.17.4/denonext/uglify-js.mjs:2:143432
at Array.map (<anonymous>)
at https://esm.sh/v126/uglify-js@3.17.4/denonext/uglify-js.mjs:2:143407
at https://esm.sh/v126/uglify-js@3.17.4/denonext/uglify-js.mjs:4:4
at https://esm.sh/v126/uglify-js@3.17.4/denonext/uglify-js.mjs:2:546
at https://esm.sh/v126/uglify-js@3.17.4/denonext/uglify-js.mjs:7:718
A workaround is using npm:uglify-js
instead of https://esm.sh/uglify-js
, but this is definitely the fault of uglify-js being incompatible with esbuild.
@alexlamsl This project does not work with many common tools, and there isn't really any reason for this. Can you take another look, and consider writing slightly less elegant code so that we can use this awesome tool in more places? Thanks!
@OBrown92 If someone does use next.js I solved it like the below:
const path = require('path'); const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }); module.exports = withBundleAnalyzer({ webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { config.module.rules.push({ test: path.resolve(__dirname, 'node_modules/uglify-js/tools/node.js'), loader: 'null-loader', }); // Important: return the modified config return config; }, ... }
@PaulKushch I tried with nextjs 13.4.17 with the pages api but It's not working. mjml works fine without any workarounds when i install directly in next app but it breaks when I import mjml from a different custom package in a monorepo
I'm building a vue app and using webpack to bundle it.
This line var UglifyJS = require("uglify-js"); causes the following:
tools sync?6ded:2
Uncaught Error: Cannot find module '../lib/utils.js' at Function.webpackEmptyContext [as resolve] (eval at ./node_modules/uglify-js/tools sync recursive (app.js:5165),:2:10)
at eval (node.js?c35f:17)
at Array.map ()
at eval (node.js?c35f:16)
at Object../node_modules/uglify-js/tools/node.js (app.js:5176)
at webpack_require (app.js:724)
at fn (app.js:101)
at eval (util.js?c276:4)
at Module../src/libs/util.js (app.js:6383)
at webpack_require (app.js:724)
and how can fix it