'Using formula.js on vue.js
I am trying to use formulja.js in a Vue project. When I import it and try to use PPMT function I am getting this error. I can't define what the error is and how to solve it. Please can someone help
ERROR Failed to compile with 1 error 5:23:41 PM
error in ./node_modules/@formulajs/formulajs/lib/esm/index.mjs
Module parse failed: Unexpected token (1453:25)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| }
|
> delimiter = delimiter ?? '';
|
| let flatArgs = flatten(args);
@ ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Table.vue?vue&type=script&lang=js& 59:0-45 74:24-33
@ ./src/components/Table.vue?vue&type=script&lang=js&
@ ./src/components/Table.vue
@ ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Home.vue?vue&type=script&lang=js&
@ ./src/components/Home.vue?vue&type=script&lang=js&
@ ./src/components/Home.vue
@ ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
@ ./src/App.vue?vue&type=script&lang=js&
@ ./src/App.vue
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.178.69:8081&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
How I am using it
<script>
import formulajs from "@formulajs/formulajs"
export default {
data() {
return {
rate: 0,
pv: 0,
nper: 0,
};
},
computed:{
totalPPMT() {
let per = 1;
let ppmt = 0
while(this.nper >= 0){
let calc_ppmt = formulajs.PPMT(this.rate,per,this.nper,this.pv,0,0)
per++
ppmt += calc_ppmt
}
return ppmt;
},
},
<script/>
Solution 1:[1]
I solved the problem? Convert the formulajs package in node_modules to babel through vue.config.js?
module.exports = {
transpileDependencies: ['@formulajs/formulajs']
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | James |