0
我在Chrome Canary版本60.0.3102.0中嘗試了ES2015模塊。我的script.js文件讀取這樣的:在加納利用ES2015模塊提取
import {fetchJSON} from './functions/fetchJSON.js';
const configFile = 'config.json';
const init =() => {
fetchJSON(configFile)
.then((data) => { // code fails here at ln.7
console.log(data);
})
.catch(error => console.log(error));
};
init();
和我fetchJSON.js文件讀取這樣的:
export function fetchJSON(url) {
const fetchJSON = fetch(url)
.then(response => response.json())
.then(data => {
console.log(data); // data exists and is reported in the console
return data;
});
}
,我發現了錯誤:
script.js:7 Uncaught TypeError: Cannot read property 'then' of undefined
at init (script.js:7)
at script.js:14
所以我其實並不需要: '。然後(數據=> {返回的數據;});' – interwebjill