Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 网页包弄乱了字符顺序,导致意外的令牌错误_Typescript_Webpack_Xstate - Fatal编程技术网

Typescript 网页包弄乱了字符顺序,导致意外的令牌错误

Typescript 网页包弄乱了字符顺序,导致意外的令牌错误,typescript,webpack,xstate,Typescript,Webpack,Xstate,我知道这个标题不是很有描述性,但找不到更好的词来形容它。我正在使用“xstate”库,生成结果导致“意外令牌”错误 这是我的webpack.config.js: var WebpackBuildNotifierPlugin = require('webpack-build-notifier'); var webpackConfig = { entry: "./src/App.tsx", output: { filename: "bundle.js",

我知道这个标题不是很有描述性,但找不到更好的词来形容它。我正在使用“xstate”库,生成结果导致“意外令牌”错误

这是我的webpack.config.js:

var WebpackBuildNotifierPlugin = require('webpack-build-notifier');

var webpackConfig = { 
    entry: "./src/App.tsx",
    output: {
        filename: "bundle.js",
        path: __dirname + "/dist"
    },
    plugins: [
        new WebpackBuildNotifierPlugin({
          title: "Build",
          suppressSuccess: false
        })
    ],
    // Enable sourcemaps for debugging webpack's output.
    devtool: "source-map",
    mode:'development',
    resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [".ts", ".tsx", ".js", ".json"]
    },
    module: {
        rules: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
            { test: /\.css$/,  loader: 'style-loader!css-loader' },
            { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' },
            { test: /\.(jpg|png|svg|gif|css)$/, exclude: /fabric\.css$/, loader: 'file-loader' }
        ]
    }
};


module.exports = [
    webpackConfig
];
构建代码后,bundle.js的部分如下所示,这导致了“意外令牌”错误:

u
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")))ndefined 
Xstate以以下方式导入:

import * as React from 'react';
import { Machine, interpret } from 'xstate';

interface AppRootState{
    currentState:any
}

export class AppRoot extends React.Component<{}, AppRootState>{

    service = interpret(appRootMachine).onTransition((current)=>{
        this.setState({current});
    });

    constructor(){
        super({});
        this.state = {
            currentState:this.service.initialState
        };
    }

    componentDidMount() {
        this.service.start();
    }

    componentWillUnmount() {
       this.service.stop();
    }
    ///Rest of the code
}

import*as React from'React';
从'xstate'导入{Machine,explain};
接口批准状态{
当前状态:任何
}
导出类approt扩展React.Component{
服务=解释(批准机器).onTransition((当前)=>{
this.setState({current});
});
构造函数(){
超级({});
此.state={
currentState:this.service.initialState
};
}
componentDidMount(){
this.service.start();
}
组件将卸载(){
this.service.stop();
}
///代码的其余部分
}

很难消除您可能拥有的所有设置变量,但以下是我尝试过的方法,以及在尝试复制您的问题时对我有效的方法:

我按照《使用React&Webpack设置的typescript指南》中的说明进行了操作

一旦我达到了一切都正常工作的程度,我就用您在问题中提供的内容替换了“Hello”组件内容,“working”组件的结果如下:

import * as React from 'react';
import { Machine, interpret } from 'xstate';

export interface AppRootProps {}
export interface AppRootState {
  currentState: any;
  current: any;
}

const appRootMachine = Machine({
  id: 'toggle',
  initial: 'inactive',
  states: {
    inactive: { on: { TOGGLE: 'active' } },
    active: { on: { TOGGLE: 'inactive' } }
  }
});

export class AppRoot extends React.Component<AppRootProps, AppRootState> {
  service = interpret(appRootMachine).onTransition((current) => {
    this.setState({ current });
  });

  constructor() {
    super({});
    this.state = {
      currentState: this.service.initialState,
      current: {}
    };
  }

  componentDidMount() {
    this.service.start();
  }

  componentWillUnmount() {
    this.service.stop();
  }
  render() {
    return (
      <h1>
        Current state:
        {this.state.currentState && this.state.currentState.value}
      </h1>
    );
  }
}

import*as React from'React';
从'xstate'导入{Machine,explain};
导出接口ApprotProps{}
导出接口ApprotState{
当前状态:任何;
当前:任何;
}
const approtMachine=机器({
id:'切换',
首字母:'不活动',
国家:{
非活动:{on:{TOGGLE:'active'}},
活动:{on:{TOGGLE:'inactive'}}
}
});

Exchange类Office扩展Actudio。您应该考虑将来使用XSTATE的组件,并注意这里的用法示例,因为它们显示了比这里所示的更好的用法来解决您的问题。

请提供导入时的运行时代码。xstate@Ciamas你解决了这个问题吗?我看不出这是xstate的问题或它的使用问题,而是一个Web包/键入错误的问题?实际上不是,我没有时间@驯獾