ClojureScript

"No such namespace" warning when referring to JS module namespace without using alias

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: 1.9.76
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Currently, when requiring a JS module it is not possible to refer to it using the original namespace. For example, the following code will result in a warning:

(ns my-calculator.core
  (:require [my.calc]))

(println (my.calc/add 5 5))
WARNING: No such namespace: my.calc, could not locate my/calc.cljs, my/calc.cljc, or Closure namespace "" at line 4 src/my_calculator/core.cljs
WARNING: Use of undeclared Var my.calc/add at line 4 src/my_calculator/core.cljs

And the resulting JavaScript will throw the following error:

Uncaught ReferenceError: my is not defined

However, defining an alias for the JS module and using it works fine, for example:

(ns my-calculator.core
  (:require [my.calc :as calc]))

(println (calc/add 5 5))

Here is a minimal repo to reproduce this problem: https://github.com/mneise/my-calculator.

Activity

Hide
Maria Geller added a comment -

Added a patch for this.

Since JS modules are loaded using the new name created by the Google Closure compiler during module conversion, we always need to add an alias from the name given in the :provides compiler option to the new name.

Show
Maria Geller added a comment - Added a patch for this. Since JS modules are loaded using the new name created by the Google Closure compiler during module conversion, we always need to add an alias from the name given in the :provides compiler option to the new name.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: