Ran into a problem today at work, wondering if anyone could offer some guidance. Im trying to accomplish roughly the following described below.
Files im working with:
script.js : node script written using node version that does not support the use of es6 syntax (particulary using import keyword). script.js aims to read the contents of config.js
//config.js import _ from 'npm:lodash' import foo from '../otherRandomFile.js' var configObject = { randomConfigOne: true, randomConfigTwo: false } export default configObject; //script.js var config = require('../app/config.js) //cannot console log as below because script barfs //due to import being a reserved wrk console.log(config.randomConfigOne);
Question: What do I have to do in script.js so that I can access the object exported by the config.js file. Right now the script is barfing about the fact that I'm trying to use es6 syntax in the file I'm accessing
console.log(config.default.randomConfigOne);
thus your module can export multiple items when you use
export default
it stored at module.default
babel converts export default {}
into
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {};
in such cases - just check transpiled code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.