ES6 - HSVtoRGBToRef Uncaught TypeError

Using HSVtoRGBToRef in ES6 project causes Uncaught TypeError.
Can someone explain what might be the cause?

Test code:

import * as BABYLON from '@babylonjs/core/Legacy/legacy';

let scc = new BABYLON.Color3(0.2, 0.2, 0.2);
BABYLON.Color3.HSVtoRGBToRef(0, 0, 0, scc);

Error:
Uncaught TypeError: babylonjs_core_Legacy_legacy__WEBPACK_IMPORTED_MODULE_0_.Color3.HSVtoRGBToRef is not a function

pinging our module masterchief @sebavan

w0000t sounds pretty weird indeed, I will try that ASAP and let you know.

Just tried

import * as BABYLON from '@babylonjs/core/Legacy/legacy';
var scc = new BABYLON.Color3(0.2, 0.2, 0.2);
BABYLON.Color3.HSVtoRGBToRef(0, 0, 0, scc);
console.log(scc);

and it works without issue:

What version of @babylonjs/core do you use ? could you try the latest @preview ???

Hi @sebavan !
How can I get the latest version?

This is my package.json:

{
  "name": "babylonjs-webpack-boilerplate",
  "version": "1.0.0",
  "description": "This is a BabylonJS + Webpack boilerplate to work with typescript and/or es6",
  "main": "index.js",
  "scripts": {
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
    "dev": "webpack-dev-server --config ./webpack.config.js --open --mode development",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Paul Orac",
  "license": "MIT",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.6.1",
    "compression-webpack-plugin": "^1.1.11",
    "cross-env": "^5.1.4",
    "css-loader": "^0.28.11",
    "html-webpack-plugin": "^3.2.0",
    "style-loader": "^0.21.0",
    "ts-loader": "^4.2.0",
    "typescript": "^2.8.3",
    "uglifyjs-webpack-plugin": "^1.2.5",
    "webpack": "^4.6.0",
    "webpack-cli": "^2.0.15",
    "webpack-dev-server": "^3.1.3",
    "webpack-livereload-plugin": "^2.1.1"
  },
  "dependencies": {
    "@babylonjs/core": "^4.0.3",
    "@babylonjs/gui": "^4.0.3",
    "@babylonjs/inspector": "^4.0.3",
    "@babylonjs/loaders": "^4.0.3",
    "@babylonjs/materials": "^4.0.3",
    "@babylonjs/post-processes": "^4.0.3",
    "@babylonjs/procedural-textures": "^4.0.3",
    "@babylonjs/serializers": "^4.0.3"
  }
}

And this is my webpack.config.js

let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let LiveReloadPlugin = require('webpack-livereload-plugin');
const path = require('path');

module.exports =  {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname,'dist'),
    filename: 'bundle.js'
  },
  resolve: {
    modules: [path.resolve(__dirname, '/src'), 'node_modules/'],
    descriptionFiles: ['package.json'],
    extensions : ['.js', '.ts', '.tsx']
  },
  module: {
    rules: [
      {
        use: 'babel-loader',
        test: /\.js$/,
        exclude: /node_modules/
      },
      {
        use: 'ts-loader',
        test: /\.tsx?$/,
        exclude: /node_modules/
      },
      {
        use: ['style-loader', 'css-loader'],
        test: /\.css$/
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'index.html'
    }),
    new LiveReloadPlugin()
  ],
  externals: {
    oimo: 'OIMO', //or true
    cannon: 'CANNON', //or true
    earcut: 'EARCUT'
  }
};

const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
var CompressionWebpackPlugin = require('compression-webpack-plugin');

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map';
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),

    new UglifyJsPlugin({
      sourceMap: true
    }),

    new CompressionWebpackPlugin({
      asset: '[path].gz[query]',
      algorithm: 'gzip',
      test: /\.(js|ts|vue|json|png|jpg|gif|svg)$/,
      threshold: 10240,
      minRatio: 0.8
    }),

    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ]);
}

install @babylonjs/core@preview and the same for all the dependencies

One piece of advice as well could you try to rename import * as BABYLON… to import * as MYBABYLON to prevent some possible conflicts with the BABYLON global just to be safe ?

Hi @sebavan !
I can confirm that @babylonjs/core@preview works without Uncaught TypeError.

1 Like