小编set*_*ana的帖子

使用Webpack和React的意外令牌

我是TypeScript的新手,对React来说相对较新,只是想尝试遵循React和Webpack教程.通过一些搜索,我设法解决了大部分问题,因为它有点过时,除了一个.当我尝试运行Webpack来转换Typescript时,我得到:

ERROR in ./src/index.tsx
Module parse failed: /home/X/Projects/react-typescript-tutorial/src/index.tsx Unexpected token (7:4)
You may need an appropriate loader to handle this file type.
| 
| ReactDOM.render(
|     <Hello compiler="TypeScript" framework="React" />,
|     document.getElementById("example")
| );
Run Code Online (Sandbox Code Playgroud)

我尝试了上一个问题中提到的解决方案,但它对我的情况没有影响.我不确定这是awesome-typescript-loader在这一点上的问题还是Webpack的问题.

我的webpack.config.js文件:

module.exports = {
    entry: "./src/index.tsx",
    output: {
        filename: "bundle.js",
        path: __dirname + "/dist"
    },

    devtool: "source-map",

    resolve: {
        extensions: ["*", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },

    module: {
        loaders: [
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" }
        ],

        rules: [
            { …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs webpack

3
推荐指数
1
解决办法
703
查看次数

标签 统计

reactjs ×1

typescript ×1

webpack ×1