【问题标题】:ecmascript 6 - not a constructor at Object errorecmascript 6 - 不是对象错误的构造函数
【发布时间】:2018-01-18 17:53:11
【问题描述】:

我开始突然收到这个错误。我正在使用 webpack 和 babel。 在我的存储类中一切正常。

我正在使用这样的 storege 类

import Storage from './storage'

let DB = new Storage();

我没有更新通天塔。我不知道错误的来源也许是 webpack?

  • “babel-core”:“^6.25.0”
  • “babel-loader”:“^7.1.1”
  • "babel-preset-es2015": "^6.24.1"
  • “webpack”:“^3.3.0”

我的 storage.js 看起来像这样

import localStorage from './localStorage'
import View from './view'

let lStore = new localStorage();
let V = new View();

let data = (lStore.get('todo')) ? JSON.parse(lStore.get('todo')):{
    todo: [],
    complated: []
};

export default class Storage {

addItem(text, id){
    /* Store  */
    this.store(text);

    /* Add HTML Item */
    V.addToDOM(text, id);
}

store(text){
    data.todo.push(text);
    data.complated.push(false);

    //sync
    this.objectLocalStorage();
}

list() {
    return data;
}

updateItem(id, complated){
    /* */
    data.complated[id] = complated;

    //sync
    this.objectLocalStorage();
}

deleteItem(id){
    data.complated.splice(id, 1);
    data.todo.splice(id, 1);

    //sync
    this.objectLocalStorage();
}

/* Local Storage Set-Update-Sync */
objectLocalStorage() {
    lStore.set('todo', JSON.stringify(data));
}}

【问题讨论】:

  • update Babel“最近”了吗? ./storage.js 长什么样子,之前转换成什么?
  • 请同时包含storage.js,或至少包含相关导出。
  • ./storage 看起来如何?你那里有默认导出吗?

标签: javascript webpack babeljs


【解决方案1】:

试试:

import { Storage } from './storage'

let DB = new Storage();

Storage 可能不是 storage.js 文件的默认导出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 2022-01-05
    相关资源
    最近更新 更多