I'm wondering why this is not valid on an application created using create-react-app:
/***** myLib.js *****/
const multiplyByTwo = val => val * 2;
export default { multiplyByTwo };
Nor:
/***** myLib.js *****/
let multiplyByTwo = val => val * 2;
export default { multiplyByTwo };
Neither:
/***** myLib.js *****/
function multiplyByTwo(val) { return val * 2; };
export default { multiplyByTwo };
Then, in another file:
/***** main.js *****/
import { multiplyByTwo } from './myLib'
console.log(multiplyByTwo(10));
When I try to compile it, I get this error:
Failed to compile.
./src/main.js
Attempted import error: 'multiplyByTwo' is not exported from './myLib'
However, this is valid:
/***** myLib.js *****/
export const multiplyByTwo = val => val * 2;
Also this:
/***** myLib.js *****/
export let multiplyByTwo = val => val * 2;
let multiplyByTwo = val => val * 2; export default { multiplyByTwo };you should import it likeimport helper from './myLib'and use it likehelper.multiplyByTwo(3)