Difficulty generating a Bundle.js file

Asked

Viewed 35 times

0

I’m testing the Babel For this I have a file 'matematica.js' which for now exports only one function

const soma = function(a,b){
    return a - b
}
export default {soma}

This function is imported into index.js'

import soma from './matematica.js'
var a = 10;
var b = 5;
onsole.log(soma(a,b))

I’m running the Abel this way

babel ./index.js -o ./bundle.js

which generates the following file

"use strict";

var _mat = require("./matematica.js");

var a = 10;
var b = 5;
console.log((0, _mat.soma)(a, b));

but on the console appears the following message

Bundle.js:3 Uncaught Referenceerror: require is not defined at Bundle.js:3 (Anonymous) @Bundle.js:3

Someone could help by showing my transpilation error.

  • Babel is a transpilator, not a module bundler. To do this, you should also use a tool like Webpack. If you are looking for agility, Parcel can be simpler.

  • I think you should have export default soma instead of export default {soma}

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.