ERROR - variable console is undeclared

2,126 views
Skip to first unread message

Felix Wong

unread,
Oct 15, 2013, 12:08:53 PM10/15/13
to closure-comp...@googlegroups.com
I am using simple compilation level and the compiler is complaining about the variable console is not defined.

console.log("Hello World");

Am I missing an extern or a compiler option would allow this?

Thanks!

Dimitris Vardoulakis

unread,
Oct 15, 2013, 12:16:25 PM10/15/13
to closure-comp...@googlegroups.com
With the default options for simple mode, you shouldn't be getting this warning, for console or another free variable with any name.

java -jar build/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js your_js_code

How exactly are you calling the compiler?


--
 
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Dimitris

Felix Wong

unread,
Oct 15, 2013, 12:27:01 PM10/15/13
to closure-comp...@googlegroups.com
I am using jscomp Ant task with the following options.

        <jscomp compilationLevel="simple" warning="verbose" debug="false"
                output="${build.dir}/cjs/test.min.js"
                languageIn="ECMASCRIPT5_STRICT"
                sourceMapOutputFile="${build.dir}/cjs/test.js.map"
                sourceMapFormat="V3">
                
            <sources dir="${basedir}/resources/WEB-CONTENT/js">
                <file name="test.js"/>
            </sources>
        </jscomp>


On Tuesday, October 15, 2013 12:16:25 PM UTC-4, Dimitris Vardoulakis wrote:
With the default options for simple mode, you shouldn't be getting this warning, for console or another free variable with any name.

java -jar build/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js your_js_code

How exactly are you calling the compiler?
On Tue, Oct 15, 2013 at 9:08 AM, Felix Wong <fmh...@gmail.com> wrote:
I am using simple compilation level and the compiler is complaining about the variable console is not defined.

console.log("Hello World");

Am I missing an extern or a compiler option would allow this?

Thanks!

--
 
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Dimitris

Dimitris Vardoulakis

unread,
Oct 15, 2013, 12:38:27 PM10/15/13
to closure-comp...@googlegroups.com
You're getting the warning b/c you choose the verbose-warnings option. To use the console, you must use the externs in this file




To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Dimitris

Dimitris Vardoulakis

unread,
Oct 15, 2013, 12:44:05 PM10/15/13
to closure-comp...@googlegroups.com
As far as I can tell, these externs are provided by default if you call the compiler from the command line, but not if you're using ant.
--
Dimitris

Nick Santos

unread,
Oct 15, 2013, 1:08:30 PM10/15/13
to closure-compiler
I don't believe we've ever provided a default externs that declared
the 'console' global. I usually provide my own externs with

/** @type {Console} */
var console;

Felix Wong

unread,
Oct 15, 2013, 1:47:32 PM10/15/13
to closure-comp...@googlegroups.com
With warning level set to VERBOSE, Closure Compiler will complain about console.  I have to provide my own extern for console as Nick pointed out.

Thanks!

Kyaw

unread,
Oct 17, 2013, 12:57:32 AM10/17/13
to closure-comp...@googlegroups.com
You can use window.console or goog. global.console
Reply all
Reply to author
Forward
0 new messages