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

Maria Geller made changes -
Field Original Value New Value
Assignee Maria Geller [ mneise ]
Maria Geller made changes -
Status Open [ 1 ] In Progress [ 3 ]
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.
Maria Geller made changes -
Attachment CLJS-1820.patch [ 16065 ]
David Nolen made changes -
Assignee Maria Geller [ mneise ] David Nolen [ dnolen ]
David Nolen made changes -
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Completed [ 1 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: