google / closure-compiler-npm

Package for managing and documenting closure-compiler for use via npm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compilation for browser via webpack fails

divs1210 opened this issue · comments

Webpack Config

const path = require('path');
const ClosurePlugin = require('closure-webpack-plugin');
 
module.exports = {
    entry: './core.js',
    output: {
        filename: 'out.js',
        path: path.resolve(__dirname, 'dist'),
    },
    optimization: {
        concatenateModules: false,
        minimizer: [
            new ClosurePlugin(
                {
                    mode: 'AGGRESSIVE_BUNDLE',
                    platform: 'javascript'
                }, {
                // compiler flags here
                //
                // for debugging help, try these:
                //
                // formatting: 'PRETTY_PRINT'
                // debug: true,
                // renaming: false
            })
        ]
    }
};

Output

ERROR in ./node_modules/google-closure-compiler/lib/node/closure-compiler.js
Module not found: Error: Can't resolve 'child_process' in '/Users/divyansh/repos/my-project/node_modules/google-closure-compiler/lib/node'
 @ ./node_modules/google-closure-compiler/lib/node/closure-compiler.js 26:14-38
 @ ./node_modules/google-closure-compiler/index.js
 @ ./core.js

ERROR in ./node_modules/clone-stats/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/divyansh/repos/my-project/node_modules/clone-stats'
 @ ./node_modules/clone-stats/index.js 1:11-24
 @ ./node_modules/vinyl/index.js
 @ ./node_modules/google-closure-compiler/lib/gulp/index.js
 @ ./node_modules/google-closure-compiler/index.js
 @ ./core.js

ERROR in ./node_modules/google-closure-compiler-js/jscomp.js
Module not found: Error: Can't resolve 'fs' in '/Users/divyansh/repos/my-project/node_modules/google-closure-compiler-js'
 @ ./node_modules/google-closure-compiler-js/jscomp.js 7381:177-190
 @ ./node_modules/google-closure-compiler/index.js
 @ ./core.js

ERROR in ./node_modules/google-closure-compiler/lib/logger.js
Module not found: Error: Can't resolve 'fs' in '/Users/divyansh/repos/my-project/node_modules/google-closure-compiler/lib'
 @ ./node_modules/google-closure-compiler/lib/logger.js 28:11-24
 @ ./node_modules/google-closure-compiler/lib/node/closure-compiler-js.js
 @ ./node_modules/google-closure-compiler/index.js
 @ ./core.js

ERROR in ./node_modules/google-closure-compiler/lib/grunt/vinyl-stream.js
Module not found: Error: Can't resolve 'fs' in '/Users/divyansh/repos/my-project/node_modules/google-closure-compiler/lib/grunt'
 @ ./node_modules/google-closure-compiler/lib/grunt/vinyl-stream.js 25:11-24
 @ ./node_modules/google-closure-compiler/lib/grunt/index.js
 @ ./node_modules/google-closure-compiler/index.js
 @ ./core.js

ERROR in ./node_modules/google-closure-compiler-java/compiler.jar 1:2
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
 @ ./node_modules/google-closure-compiler-java/index.js 17:17-50
 @ ./node_modules/google-closure-compiler/lib/node/closure-compiler.js
 @ ./node_modules/google-closure-compiler/index.js
 @ ./core.js

Update

Switching to using google-closure-compiler-js directly works!
Not sure if its API is public/stable anymore, though.

Looks like closure-compiler-js is not closure compiler compatible yet. ☹️
It does not build in advanced mode.
Any possibility of this changing in the future?

This is pretty annoying.

This is a webpack specific issue and not one for the main closure-compiler distribution. Please move the issue here: https://github.com/webpack-contrib/closure-webpack-plugin

The JS version of Closure Compiler is not compatible with advanced optimizations - I'm not convinced this is a webpack-specific issue. In case this is not a huge blocker for anyone else, let me specify a failing use-case:

If the JS version of the Closure Compiler becomes amenable to advanced compilation, it will become an Auto Projecting JS Specializer - fulfilling the 3rd Futamura Projection for the most popular programming language. It will (theoretically) be able to convert a given interpreter written in JS into a (source to JS) compiler - theoretically more powerful than RPython / GraalVM.

The JS version of closure-compiler is advanced mode compatible.

Your example refers to the webpack-plugin option for AGGRESSIVE_BUNDLE. That's a closure-webpack-plugin option (not a compiler option) and uses the compiler to rewrite modules. This issue is definitely in the webpack plugin (which I maintain).

Got it. Thanks for the explanation.