Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Closure primitive methods (goog.provide, goog.require, goog.define, etc) must be called at file scope. #205

Open
BeksOmega opened this issue Apr 18, 2022 · 1 comment

Comments

@BeksOmega
Copy link

Package version: 2.5.0
Node version: 14.15.0
OS: Ubuntu

Minimal example: https://github.com/BeksOmega/closure-webpack-bug

Reproduction steps

  1. Clone the linked repro.
  2. npm install
  3. npm run make-deps
  4. npm run webpack
  5. Observe the errors:
ERROR in ./closure/goog/base.js:698 from closure-compiler: Closure primitive methods (goog.provide, goog.require, goog.define, etc) must be called at file scope.
goog.forwardDeclare('Document');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ERROR in ./closure/goog/base.js:699 from closure-compiler: Closure primitive methods (goog.provide, goog.require, goog.define, etc) must be called at file scope.
goog.forwardDeclare('HTMLScriptElement');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ERROR in ./closure/goog/base.js:700 from closure-compiler: Closure primitive methods (goog.provide, goog.require, goog.define, etc) must be called at file scope.
goog.forwardDeclare('XMLHttpRequest');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ERROR in ./core/blockly.js:10 (originally at line 5) from closure-compiler: Closure primitive methods (goog.provide, goog.require, goog.define, etc) must be called at file scope.
const module = goog.require('testModule');
               ^^^^^^^^^^^^^^^^^^^^^^^^^^

Note that the entry-point file is 'core/blockly.js' because that matches the project I'm trying to convert to using webpack. See the main repository here: https://github.com/google/blockly

Expected behavior

There should be no errors when compiling with the closure-webpack-plugin.

Additional Info

I think this may be related to using a local copy of base.js? But I'm not sure. We would really like to continue using a local copy if possible so that we can remove unnecessary parts of base.js in the future.

Thank you for your time!

@ChadKillingsworth
Copy link
Member

This is likely due to the fact that base.js is manipulated to support the semantics of webpack. See https://github.com/webpack-contrib/closure-webpack-plugin/blob/master/src/dependencies/goog-base-global.js

I don't really see a path forward to using a custom version of base.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants