Raghul Selvaraj
Raghul Selvaraj

Reputation: 145

let variable conflict on closure compiler

I have 2 javascript files and each has a variable 'let logger' in file scope. And file2 imports file1.

file1.js

let logger;

file2.js

mod = require("./file1.js); let logger;

Javascript parsers(nodejs) create file scope for let variables(instead of global scope). But JSC_REDECLARED_VARIABLE_ERROR is thrown in closure compiler.

Is there any way to suppress this error?

Upvotes: 1

Views: 270

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

JS parsers do not create file scope for variables of any type. NodeJS files are modules which have a unique scope. If your file is processed as a module, it will be given a unique scope.

For commonJS modules, using the --process_common_js_modules flag of the compiler will recognize and bundle CommonJS modules.

However the Closure Compiler is primarily designed to target browsers. It's not currently designed to properly bundle code that targets NodeJS - though some users utilize the type checking functionality only for Node.

Upvotes: 1

Related Questions