我知道标题不是很具有描述性,但找不到更好的词。我正在使用“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
}