Skip to content

Uncaught TypeError: Color is not a function #434

@McLaynV

Description

@McLaynV

Hello,
I'm new to Javascript, so it is probably my problem, but I've spent a few evenings on this and wasn't able to google anything related, so here I am asking for help.

I have a simple Vue app with CSS handled by bulma. Here is a color picker and a function to change the primary color in bulma using bulma-css-vars:

<script setup lang="ts">
import { ColorUpdater } from 'bulma-css-vars';
import { ColorCallSet } from "bulma-css-vars/dist/types";
import { bulmaCssVariablesDefs } from "../bulma-generated/bulma-colors";

const colorUpdater = new ColorUpdater(bulmaCssVariablesDefs as ColorCallSet);

function setPrimaryColor(event: any) {
  const colorName = "primary";
  const color = event.target.value;

  colorUpdater.updateVarsInDocument(colorName, color);
}
</script>

<template>
  <div class="content">
    <label>Primary
      <input
        type="color"
        @change="setPrimaryColor"
        class="input is-primary"
      />
    </label>
  </div>
</template>

However, calling the setPrimaryColor function (when the <input> element value is changed or even calling colorUpdater.updateVarsInDocument(...) manually) causes the following error.

Uncaught TypeError: Color is not a function
    at stringToHsl (bulma-color-tools.js:90:30)
    at ColorUpdater.getUpdatedVars (color-updater.js:24:23)
    at ColorUpdater.updateVarsInDocument (color-updater.js:33:31)
    at setPrimaryColor (ColorPalette.vue:13:16)
    at callWithErrorHandling (runtime-core.esm-bundler.js:157:22)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:166:21)
    at HTMLInputElement.invoker (runtime-dom.esm-bundler.js:345:9)

const [h, s, l] = getHsl(Color(col)).color

export function stringToHsl(col) {
    const [h, s, l] = getHsl(Color(col)).color; // <<<< HERE IS THE ERROR THROWN IN Color(col)
    return { h, s, l };
}

I tried debugging in Chrome and playing with the Color object. My findings are here:

typeof Color: "object"
Color: Function
col: "#520f0f"
Color(col): <not available>
Color.default(col): Color2
Color.prototype(col): <not available>
Color('rgb(123,123,123)'): <not available>
Color({r:123, g:123, b:123}): <not available>
new Color(col): <not available>
Color.call(col): <not available>

I believe that Color.default(col) does the expected thing in my environment.

Could I have a different version of something? My package-lock.js says:

    "node_modules/bulma": {
      "version": "0.9.4",
      "resolved": "https://registry.npmjs.org/bulma/-/bulma-0.9.4.tgz",
      "integrity": "sha512-86FlT5+1GrsgKbPLRRY7cGDg8fsJiP/jzTqXXVqiUZZ2aZT8uemEOHlU1CDU+TxklPEZ11HZNNWclRBBecP4CQ=="
    },
    "node_modules/bulma-css-vars": {
      "version": "0.8.0",
      "resolved": "https://registry.npmjs.org/bulma-css-vars/-/bulma-css-vars-0.8.0.tgz",
      "integrity": "sha512-PhhvuZcSPlnPvgWoo/8y8QAYHCCkW2gjCcVD5P/zIyNrKwzk+I4QdDpexKtzCF7TduNNP5DQGG8InulBe5TGtg==",
      "dev": true,
      "dependencies": {
        "color": "^4.2.1",
        "css": "^3.0.0",
        "mkdirp": "^1.0.4"
      },
      "bin": {
        "bulma-css-vars": "bin/bulma-css-vars.js"
      },
      "engines": {
        "node": ">= 10.0.0"
      },
      "peerDependencies": {
        "bulma": "^0.9.3"
      }
    },
    "node_modules/color": {
      "version": "4.2.3",
      "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
      "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==",
      "dev": true,
      "dependencies": {
        "color-convert": "^2.0.1",
        "color-string": "^1.9.0"
      },
      "engines": {
        "node": ">=12.5.0"
      }
    },

And my package.json:

  "dependencies": {
    "@fortawesome/fontawesome-free": "^6.2.1",
    "@pinia/testing": "^0.0.14",
    "@vueuse/core": "^7.7.0",
    "axios": "^0.26.0",
    "bulma": "^0.9.3",
    "pinia": "^2.0.11",
    "vue": "^3.2.31",
    "vue-router": "^4.0.13"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^2.2.4",
    "bulma-css-vars": "^0.8.0",
    "cypress": "^12.1.0",
    "eslint-plugin-cypress": "^2.12.1",
    "sass": "^1.49.9",
    "typescript": "^4.6.2",
    "vite": "^2.8.5",
    "vue-tsc": "^0.32.0"
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions