andrewmcveigh / cljs-time

A clj-time inspired date library for clojurescript.
342 stars 57 forks source link

Uncaught TypeError: Cannot read property 'replace' of null #53

Closed b1412 closed 8 years ago

b1412 commented 8 years ago

My dependencies

 [com.andrewmcveigh/cljs-time "0.3.14"]
 [org.clojure/clojurescript "1.7.122" :scope "provided"]
  [lein-figwheel "0.4.1"]

Just copy code from README to get start

(def built-in-formatter (formatters :basic-date-time))
(def custom-formatter (formatters "yyyyMMdd"))
(date-time 1986 10 14)
(parse custom-formatter "20100311")

But unfortunately I got following errors in console:

Uncaught TypeError: Cannot read property 'replace' of null
cljs_time$format$old_string_replace @format.cljs:270
cljs_time$format$date_parse_pattern @ format.cljs:270
cljs_time.format.parser_fn @ format.cljs:267
cljs_time$format$parse_STAR_ @format.cljs:401
cljs_time.format.parse.cljs$core$IFn$_invoke$arity$2 @ format.cljs:408
cljs_time$format$parse @ format.cljs:409
(anonymous function) @ components.cljs:24
utils.cljs:36 Figwheel: trying to open cljs reload socket

The first function call works fine,the second one throws an exception. It is quite strange, I just use some basic api.It may be caused by some environment or version problems,but I have no idea..

b1412 commented 8 years ago

After I posted the issue,I read https://github.com/andrewmcveigh/cljs-time/issues/43. I already know why I am facing this problem and tried all the suggestions,however,it is still not working...

I am sure I am using the version 0.3.14 which used the 'old-string-replace' function to fix unparse bug,but not works for me. I got this error in console.

cljs_time.format.date_setters = new cljs.core.PersistentArrayMap(null, 8, [new cljs.core.Keyword(null,"years","years",-1298579689),(function (p1__48744_SHARP_,p2__48745_SHARP_){
return p1__48744_SHARP_.setYear(p2__48745_SHARP_);
}),new cljs.core.Keyword(null,"months","months",-45571637),(function (p1__48746_SHARP_,p2__48747_SHARP_){
return p1__48746_SHARP_.setMonth(p2__48747_SHARP_);
}),new cljs.core.Keyword(null,"days","days",-1394072564),(function (p1__48748_SHARP_,p2__48749_SHARP_){
return p1__48748_SHARP_.setDate(p2__48749_SHARP_);
}),new cljs.core.Keyword(null,"hours","hours",58380855),(function (p1__48750_SHARP_,p2__48751_SHARP_){
return p1__48750_SHARP_.setHours(p2__48751_SHARP_);
}),new cljs.core.Keyword(null,"minutes","minutes",1319166394),(function (p1__48752_SHARP_,p2__48753_SHARP_){
return p1__48752_SHARP_.setMinutes(p2__48753_SHARP_);
}),new cljs.core.Keyword(null,"seconds","seconds",-445266194),(function (p1__48754_SHARP_,p2__48755_SHARP_){
return p1__48754_SHARP_.setSeconds(p2__48755_SHARP_);
}),new cljs.core.Keyword(null,"millis","millis",-1338288387),(function (p1__48756_SHARP_,p2__48757_SHARP_){
return p1__48756_SHARP_.setMilliseconds(p2__48757_SHARP_);
}),new cljs.core.Keyword(null,"time-zone","time-zone",-1838760002),cljs_time.format.timezone_adjustment], null);
cljs_time.format.parser_sort_order_pred = (function cljs_time$format$parser_sort_order_pred(parser){
return cljs_time.internal.core.index_of.call(null,new cljs.core.PersistentVector(null, 31, 5, cljs.core.PersistentVector.EMPTY_NODE, ["YYYY","YY","Y","yyyy","yy","y","d","dd","D","DD","DDD","dth","M","MM","MMM","MMMM","dow","h","H","m","s","S","hh","HH","mm","ss","a","A","SSS","Z","ZZ"], null),parser);
});
cljs_time.format.date_format_pattern = cljs.core.re_pattern.call(null,[cljs.core.str("("),cljs.core.str(clojure.string.join.call(null,")|(",cljs.core.reverse.call(null,cljs.core.sort_by.call(null,cljs.core.count,cljs.core.keys.call(null,cljs_time.format.date_formatters))))),cljs.core.str(")")].join(''));
cljs_time.format.old_string_replace = (function cljs_time$format$old_string_replace(s,match,replacement){
return s.replace((new RegExp(match.source,"g")),replacement);
});
return s.replace((new RegExp(match.source,"g")),replacement);  // exception in this line
andrewmcveigh commented 8 years ago
Uncaught TypeError: Cannot read property 'replace' of nullcljs_time$format$old_string_replace @ format.cljs:270cljs_time$format$date_parse_pattern @ format.cljs:270cljs_time.format.parser_fn @ format.cljs:267cljs_time$format$parse_STAR_ @ format.cljs:401cljs_time.format.parse.cljs$core$IFn$_invoke$arity$2 @ format.cljs:408cljs_time$format$parse @ format.cljs:409(anonymous function) @ components.cljs:24
                                                      ^^^^

This ^^^^ bit is weird.

Any chance you can post your full project.clj or at least the :cljsbuild config?

b1412 commented 8 years ago

My full project.clj is here

(defproject my-project "0.1.0-SNAPSHOT"

  :description "FIXME: write description"
  :url "http://example.com/FIXME"

  :dependencies [[org.clojure/clojure "1.7.0"]
                 [clj-time "0.11.0"]
                 [superstring "2.1.0"]
                 [slingshot "0.12.2"]
                 [com.taoensso/timbre "4.1.1"]
                 [com.taoensso/tower "3.0.2"]
                 [environ "1.0.1"]
                 [com.infolace/excel-templates "0.3.1"]
                 [ring-webjars "0.1.1"]
                 [ring/ring-defaults "0.1.5"]
                 [ring "1.4.0"]
                 [metosin/ring-middleware-format "0.6.0"]
                 [metosin/ring-http-response "0.6.5"]
                 [bouncer "0.3.3" :exclusions [com.andrewmcveigh/cljs-time]]
                 [prone "0.8.2"]
                 [org.clojure/tools.nrepl "0.2.11"]
                 [org.clojure/clojurescript "1.7.122" :scope "provided"]
                 [spellhouse/clairvoyant "0.0-72-g15e1e44"]
                 [org.clojure/tools.reader "0.9.2"]
                 [reagent "0.5.1"]
                 [re-frame "0.4.1"]
                 [re-com "0.7.0-alpha1" :exclusions [com.andrewmcveigh/cljs-time]]
                 [reagent-forms "0.5.11"]
                 [reagent-utils "0.1.5"]
                 [alandipert/storage-atom "1.2.4"]
                 [secretary "1.2.3"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [cljs-ajax "0.3.14"]
                 [metosin/compojure-api "0.23.1"]
                 [metosin/ring-swagger-ui "2.1.2"]
                 [defun "0.2.0-RC"]
         [org.clojure/data.json "0.2.6"]
                 [com.andrewmcveigh/cljs-time "0.3.14"]
         [korma "0.4.0"] 
                 [hiccup "1.0.5"]
                 [cljs-http "0.1.37"]
                 [yesql "0.5.1"]
                 [org.freemarker/freemarker "2.3.19"]
                 [crypto-password "0.1.3"]
                 [mysql/mysql-connector-java "5.1.6"]]

  :min-lein-version "2.0.0"
  :uberjar-name "my-project.jar"
  :jvm-opts ["-server"]

  :main my-project.core

  :plugins [[lein-environ "1.0.1"]
            [lein-cljsbuild "1.1.0"]]
  :cljfmt {}
  :clean-targets ^{:protect false}
  [:target-path [:cljsbuild :builds :app :compiler :output-dir]
   [:cljsbuild :builds :app :compiler :output-to]]
  :cljsbuild
  {:builds
   {:app
    {:source-paths ["src-cljs"]
     :compiler
     {:output-to "resources/public/js/app.js"
      :externs ["react/externs/react.js"]
      :pretty-print true}}}}

  :profiles
  {:uberjar {:omit-source true
             :env {:production true}
              :hooks [leiningen.cljsbuild]
              :cljsbuild
              {:jar true
               :builds
               {:app
                {:source-paths ["env/prod/cljs"]
                 :compiler {:optimizations :advanced :pretty-print false}}}} 

             :aot :all}
   :dev           [:project/dev :profiles/dev]
   :test          [:project/test :profiles/test]
   :project/dev  {:dependencies [[ring/ring-mock "0.3.0"]
                                 [ring/ring-devel "1.4.0"]
                                 [pjstadig/humane-test-output "0.7.0"]
                                 [lein-figwheel "0.4.1"]
                                 [midje "1.6.3"]]
                  :plugins [[lein-figwheel "0.4.1"]]
                   :cljsbuild
                   {:builds
                    {:app
                     {:source-paths ["env/dev/cljs"] :compiler {:source-map true}}}} 

                  :figwheel
                  {:http-server-root "public"
                   :server-port 3449
                   :nrepl-port 7002
                   :css-dirs ["resources/public/css"]
                   :ring-handler my-project.handler/app}

                  :repl-options {:init-ns my-project.core}
                  :injections [(require 'pjstadig.humane-test-output)
                               (pjstadig.humane-test-output/activate!)]
                  ;;when :nrepl-port is set the application starts the nREPL server on load
                  :env {:dev        true
                        :port       3000
                        :nrepl-port 7000}}
   :project/test {:env {:test       true
                        :port       3001
                        :nrepl-port 7001}}})
andrewmcveigh commented 8 years ago

Hi,

Sorry about the delay in getting back to you, this issue slipped off my radar.

I've been unable to reproduce this myself, in fact with your above configuration I can't even get a REPL working due to the error:

WARNING: unable to load "cemerick.piggieback/wrap-cljs-repl" middleware

So my guess would be that you are hitting issues due to either incompatible dependencies, or conflicting versions of cljs-time.

My advice would be to rebuild your project.clj file from scratch, using the latest figwheel/clojurescript lein new figwheel project-name as a starting point, and add your required clojurescript dependencies one by one, followed by your clojure dependencies. You'll then know if one of them is breaking, if any.

andrewmcveigh commented 8 years ago

I'm closing this due to no response. Please re-open if you have something further to add.