所以最后我检查我做的一切都是正确的,但我需要第二双眼睛:
convert-lock-file.js
import yaml from 'yamljs';
export function convertYarnLockToJSON() {
yaml.load(__dirname + yarn.lock', (result) => {
console.log(result); // eslint-disable-line
});
}
获取数据.js
import convertYarnLockToJSON from '../lib/convert-lock-file';
// else where in the code:
convertYarnLockToJSON();
错误:
Uncaught TypeError: (0 , _convertLockFile2.default) is not a function
当我这样做时:console.log(convertYarnLockToJSON)
我得到未定义
。
要么是我瞎了,要么是太累了,要么是出了什么问题。我正在使用 webpack 和 babel 进行编译,以防万一。 想法?
最佳答案
我认为您需要将函数导出为导出默认值
。
或者,您可以:
import { convertYarnLockToJSON } from '../lib/convert-lock-file';
关于javascript - 无法正确导出函数,es6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47171679/