-
Notifications
You must be signed in to change notification settings - Fork 12
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
Uncaught TypeError: Color is not a function #434
Comments
Hey @McLaynV! Anyways I haven't really worked in this bulma-css-vars in the past, even bulma hasn't seen much development in the last years. That being said I'll have a look at the issue if you can share a reproduction. |
Hello @wtho, Steps to reproduce:
BTW I also experienced the #167 issue (running on Windows 10 from IntelliJ Idea). Using |
I decided to go for I'm looking at |
I faced the same error while I was migrating from Webpack v4 to Vite. This was caused due to how
In TypeScript, function () { ... } In Vite,
For now, I worked around the problem by adding the following Vite plugins to my import * as fs from 'node:fs'
import * as util from 'node:util'
import { defineConfig } from 'vite'
const readFile = util.promisify(fs.readFile)
export default defineConfig({
plugins: [
{
// For development:
//
// patches access to `Color` in `bulma-css-vars`
//
// `Color` → `Color.default`
//
// `color` is imported in `bulma-css-vars` as
//
// import * as Color from 'color'
//
// (https://github.com/wtho/bulma-css-vars/blob/892baa8dad6c5082367159c2605853d6a7973b51/lib/src/bulma-color-tools.ts#L1)
//
// this causes a compatibility issue between TypeScript and Vite (esbuild)
// `Color` is a function in TypeScript, while it is an object like the
// following in esbuild:
//
// {
// default: function () { /* expected implementation of Color */ }
// }
//
// to call the expected function in esbuild, we have to extract `default`
// from `Color`.
//
// it seems Vite bypasses `load` hooks for `node_modules` in development
// mode, so we have to transform the results of esbuild
name: 'transform-bulma-css-vars',
transform(src, id) {
if (id.includes('.vite/deps/bulma-css-vars.js')) {
const transformed = src.replace(/(\W)Color\(/g, '$1Color.default(')
return {
code: transformed,
map: null
}
}
}
},
{
// For production:
//
// while esbuild is used in development mode, @rollup/plugin-commonjs is
// used in production mode. so we need a different plugin for production
//
// patches `bulma-color-tools.js` in `bulma-css-vars`
//
// import * as Color from 'color'
// ↓
// import Color from 'color'
//
// in this way, Rollup can import Color as a function
name: 'load-bulma-css-vars',
async load(id) {
if (id.includes('bulma-css-vars')
&& id.endsWith('bulma-color-tools.js'))
{
const src = await readFile(id, 'utf8')
const replaced = src.replace(
'import * as Color from \'color\'',
'import Color from \'color\'',
)
return replaced
}
},
},
],
}) |
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 theprimary
color inbulma
usingbulma-css-vars
:However, calling the
setPrimaryColor
function (when the<input>
element value is changed or even callingcolorUpdater.updateVarsInDocument(...)
manually) causes the following error.bulma-css-vars/lib/src/bulma-color-tools.ts
Line 125 in 6a669dc
I tried debugging in Chrome and playing with the
Color
object. My findings are here: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:And my
package.json
:The text was updated successfully, but these errors were encountered: