google/closure-compiler-js

goog.module support ? "Required namespace" XXX "never defined."

orenmizr opened this issue · 6 comments

build:
tsickle (by angular team. typescript + closure annotations) = output: goog.modules -> closure compiler

always fails on goog.requires. i thought it was suppose to complete each other

fails how? What's the error message?

"Required namespace" XXX "never defined." ALWAYS after tsickle.

on goog.require(app.ctrl)
--------------------^^^^

We'll probably need a small code sample to repro. cc @alexeagle

Please file such issues on the angular/tsickle issue tracker - there is no reason to suspect a bug in closure compiler until eliminating the possibility that tsickle produces bad JS.

Zysen commented

I appear to be having the same issue. Its possible that im missing something, but the problem occurs when you specify input files in the wrong order. But when i do the same using the compiler.jar it works fine.

I am using the icecream,cone,shop example from https://github.com/google/closure-compiler/wiki/Managing-Dependencies.

// File 1 - icecream.js
goog.provide('ice.cream');
// File 2 - cone.js
goog.provide('waffle.cone');
// File 3 - shop.js
goog.provide('ice.cream.Shop');
goog.require('ice.cream');
goog.require('waffle.cone');

I will compile in the right order and then the wrong order. (based on provide/require described above).

C:\projects\closure-test>java -jar closure-compiler-v20180204.jar --js icecream.js --js cone.js --js shop.js --dependency_mode=STRICT --entry_point=goog:ice.cream.Shop
var ice={cream:{}};console.log("Ice Cream");var waffle={cone:{}};console.log("waffle.cone");ice.cream.Shop={};console.log("ice.cream.Shop");

C:\projects\closure-test>java -jar closure-compiler-v20180204.jar --js shop.js --js cone.js --js icecream.js --dependency_mode=STRICT --entry_point=goog:ice.cream.Shop
var ice={cream:{}};console.log("Ice Cream");var waffle={cone:{}};console.log("waffle.cone");ice.cream.Shop={};console.log("ice.cream.Shop");

They both work fine.

When i compile using the following javascript i get...

const fs = require("fs");
const compile = require('google-closure-compiler-js').compile;

function docompile(code){
	const flags = {
		jsCode: code,
		compilationLevel: "ADVANCED",
		dependencyMode	: "STRICT",
		entryPoint : "ice.cream.Shop"
	};

	const out = compile(flags);
	if(out.warnings.length>0){
		console.warn("Warnings");
		out.warnings.forEach(function(w){
			console.warn(w);
		});
	}
	if(out.errors.length>0){
		console.error("Errors");
		out.errors.forEach(function(w){
			console.log(w);
		});
	}
	else{
		console.log("Compilation Successful");
		console.log(out.compiledCode);
	}
	console.log("---------");
}

docompile([{src: fs.readFileSync("icecream.js").toString()}, {src: fs.readFileSync("cone.js").toString()}, {src: fs.readFileSync("shop.js").toString()}]);
docompile([{src: fs.readFileSync("shop.js").toString()}, {src: fs.readFileSync("cone.js").toString()}, {src: fs.readFileSync("icecream.js").toString()}]);

this is the output.

C:\projects\closure-test>node compile.js
Compilation Successful
console.log("Ice Cream");console.log("waffle.cone");console.log("ice.cream.Shop");
---------
Errors
{ file: 'Input_0',
  description: 'required "ice.cream" namespace not provided yet',
  type: 'JSC_LATE_PROVIDE_ERROR',
  lineNo: 3,
  charNo: 0 }
{ file: 'Input_0',
  description: 'required "waffle.cone" namespace not provided yet',
  type: 'JSC_LATE_PROVIDE_ERROR',
  lineNo: 4,
  charNo: 0 }
--------- 

The second compile fails because the sources are specified in the wrong order. But that shouldnt be the case, as compiler.jar doesn't care.
Also why does the js version not have the object definitions like compiler.jar does Example: var waffle={cone:{}};

Apologies if im missing something obvious.

Entrypoint should be goog:ice.cream.Shop