I receive this error (screenshot) from my code with custom plugin:
vue-router.esm.js:2316 TypeError: Cannot set properties of undefined (setting '__esModule')
at bp (HyperFormula.js:3:8)
at Ap (Config.js:13:21)
at u4 (index.js:15:15)
at m_ (Unparser.js:7:14)
at yz (ParserWithCaching.js:14:17)
at pr (index.js:13:26)
at Wr (AbsoluteCellRange.js:9:15)
at EY (DependencyGraph.js:5:26)
at qi (index.js:5:24)
at we (Cell.js:7:24)
Plugin code:
import { quartile } from '@/addons/quartiles';
import {
HyperFormula,
FunctionPlugin,
FunctionArgumentType,
CellError,
ErrorType,
} from 'hyperformula';
import { ErrorMessage } from './hyperformula-error-message'; // copy of hyperformula/es/error-message.js
export default (maxRows = 1, maxColumns = 1) => {
class MyFunctionsPlugin extends FunctionPlugin {
percentile({ args }, currentCell) {
const hot = window.$root?.handsontableGetTable();
if (!hot || args.length > 2 || !args.length) {
return new CellError(ErrorType.ParseError, ErrorMessage.NumberCoercion);
}
const range = [
Math.min(
currentCell.row + args[0].start.row,
currentCell.row + args[0].end.row
),
Math.min(
currentCell.col + args[0].start.col,
currentCell.col + args[0].end.col
),
Math.max(
currentCell.row + args[0].start.row,
currentCell.row + args[0].end.row
),
Math.max(
currentCell.col + args[0].start.col,
currentCell.col + args[0].end.col
),
];
const rangeValues = [];
let percent = null;
if (args[1].type.toUpperCase() === 'CELL_REFERENCE') {
percent = hot.getDataAtCell(
currentCell.row + args[1].reference.row,
currentCell.col + args[1].reference.col
);
} else {
percent = args[1].value;
}
for (let row = range[0]; row <= range[2]; row++) {
for (let col = range[1]; col <= range[3]; col++) {
rangeValues.push(parseFloat(hot.getDataAtCell(row, col)));
}
}
return quartile(rangeValues, percent);
}
value({ args }, formulaAddress) {
return this.runFunction(
args,
formulaAddress,
this.metadata('VALUE'),
(val) => {
if (!isNaN(val) && !isNaN(parseFloat(val))) {
return parseFloat(val);
} else {
return new CellError(ErrorType.VALUE, ErrorMessage.NumberCoercion);
}
}
);
}
formulatextx(ast, formulaAddress) {
const noArgCallback = () =>
new CellError(ErrorType.NA, ErrorMessage.WrongArgNumber);
const refCallback = (cellReference) => {
return (
this.serialization.getCellFormula(cellReference) ??
new CellError(ErrorType.NA, ErrorMessage.Formula)
);
};
return this.runFunctionWithReferenceArgument(
ast.args,
formulaAddress,
this.metadata('FORMULATEXTX'),
noArgCallback,
refCallback
);
}
}
MyFunctionsPlugin.implementedFunctions = {
PERCENTILE: {
method: 'percentile',
},
VALUE: {
method: 'value',
parameters: [{ argumentType: FunctionArgumentType.STRING }],
},
FORMULATEXTX: {
method: 'formulatextx',
parameters: [{ argumentType: FunctionArgumentType.NOERROR }],
},
};
HyperFormula.registerFunctionPlugin(MyFunctionsPlugin, {
enGB: {
PERCENTILE: 'PERCENTILE',
VALUE: 'VALUE',
FORMULATEXTX: 'FORMULATEXTX',
},
});
const hf = HyperFormula.buildEmpty({
licenseKey: 'internal-use-in-handsontable',
precisionRounding: 6,
maxColumns,
maxRows,
});
hf.addNamedExpression('TRUE', '=TRUE()');
hf.addNamedExpression('FALSE', '=FALSE()');
return hf;
};
What I’m doing wrong? How to fix this issue?
Update:
The error described above occurs after build.
In dev mode occurs next one:
Cannot convert undefined or null to object
at Function.values (<anonymous>)
at TranslationPackage.checkErrors (TranslationPackage.js:87:30)
at new TranslationPackage (TranslationPackage.js:17:10)
at buildTranslationPackage (TranslationPackage.js:103:10)
at HyperFormula.registerLanguage (HyperFormula.js:284:50)
at index.js:63:14
It happens because ErrorType
inside of TranslationPackage.checkErrors
is undefined. But it’s regular import and I don’t understand why it occurs.