goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 322 forks source link

Uncaught TypeError: _alt2.default is not a constructor #681

Closed cssxn closed 7 years ago

cssxn commented 7 years ago

who can help me! I got this error. @goatslacker

these are my code and package.json . This error that I tought it's about webpack'preset to es5.

alt

import Alt from 'alt';

const alt = new Alt();

export default alt;

actions

import alt from '../../alt';

class DashboardActions {

    getSummary() {
        console.log(111)
        $.ajax({url:'/v1/statistics/summary?data'})
        .done((data) => {
            console.log(data)
            this.actions.getSummarySuccess(data);
        })
        .fail((jqXhr) => {
            this.actions.getSummaryFail(jqXhr);
            console.log(jqXhr)
        });
    }

}

export default alt.createActions(DashboardActions);

store

import alt from '../../alt';
import DashboardActions from './DashboardActions';

class DashboardStore {
    constructor() {
        this.bindActions(DashboardActions);
    }

    onGetSummarySuccess(data) {
        console.log('onGetSummarySuccess:',data);
    }

    onGetSummaryFail(jqXhr) {
        console.log('onGetSummaryFail:',jqXhr);
    }

}

export default alt.createStore(DashboardStore);

component

import React from 'react';
import DashboardStore from './DashboardStore';
import DashboardActions from './DashboardActions';

class DashboardV1 extends React.Component {

    constructor(props,context){
        super(props,context)
        this.state = DashboardStore.getState();
        this.onChange = this.onChange.bind(this);
    }

    componentDidMount() {
       DashboardStore.listen(this.onChange);
       DashboardActions.getSummary();
    }

    componentWillMount() {
        DashboardStore.unlisten(this.onChange);
    }

    onChange(state) {
        this.setState(state);
    }

    // forward 
    forwardToRoute(routerPath) {
        this.context.router.push(routerPath);
    }

    render() {
        return (
                <div></div>
            );
    }

}

DashboardV1.contextTypes = {
    router: React.PropTypes.object.isRequired
}
export default DashboardV1;

package.json

{
  "name": "web_webpack",
  "version": "1.0.0",
  "description": "",
  "main": "config.js",
  "scripts": {
    "prestart": "webpack --config webpack.dll.config.js",
    "start": "webpack-dev-server --config webpack.dev.config.js",
    "build": "webpack --config webpack.prod.config.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "alt": "^0.18.5",
    "alt-utils": "^1.0.0",
    "pubsub-js": "^1.5.3",
    "react": "^15.3.1",
    "react-addons-css-transition-group": "^15.3.1",
    "react-bootstrap": "^0.30.3",
    "react-dom": "^15.3.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.7.0",
    "react-router-bootstrap": "^0.23.1",
    "redux": "^3.6.0"
  },
  "devDependencies": {
    "babel": "^6.5.2",
    "babel-core": "^6.14.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-react": "^6.11.1",
    "bower": "^1.7.9",
    "css-loader": "^0.24.0",
    "node-sass": "^3.8.0",
    "react-hot-loader": "^1.3.0",
    "sass-loader": "^4.0.1",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.15.1"
  }
}
goatslacker commented 7 years ago

What is it if its not a constructor?

console.log it

davidjlongo commented 7 years ago

Was there a solution to this? I am running into the same issue.

maxcc0 commented 7 years ago

This works: import Alt from 'alt/lib' var alt = new Alt(); module.exports = alt;

rcarcasses commented 7 years ago

@maxcc0 it worked for me, thanks!

elaich commented 7 years ago

If someone can update the docs on npmjs.com,

https://www.npmjs.com/package/alt

Replace import Alt from 'alt' by import Alt from 'alt/lib', that would save people time :p