Node.js Web包类型脚本错误意外标记

Node.js Web包类型脚本错误意外标记,node.js,typescript,webpack,ts-loader,Node.js,Typescript,Webpack,Ts Loader,我试图用Webpack运行Typescript,但似乎遇到了问题。一切正常,直到我为变量引入打字(例如,color:string;)。有人能帮我吗 package.json: { ... "devDependencies": { "browser-sync": "^2.26.3", "browser-sync-webpack-plugin": "^2.2.2", "html-webpack-plugin": "^3.2.0", "ts-loader": "

我试图用Webpack运行Typescript,但似乎遇到了问题。一切正常,直到我为变量引入打字(例如,
color:string;
)。有人能帮我吗

package.json:

{
  ...
  "devDependencies": {
    "browser-sync": "^2.26.3",
    "browser-sync-webpack-plugin": "^2.2.2",
    "html-webpack-plugin": "^3.2.0",
    "ts-loader": "^5.3.0",
    "typescript": "^3.1.4",
    "webpack": "^4.23.1",
    "webpack-cli": "^3.1.2"
  },
  ...
}
webpack.config.js

module.exports = {
    ...
    module: {
        rules: [{
            exclude: NODE_DIR, /** path to node_modules folder */
            test: /\.tsx?$/,
            use: {
                loader: 'ts-loader'
            }
        }]
    },
    output: output = {
        filename: 'bundle.js',
        path: DIST_DIR /** path to dist folder */
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx']
    },
}
tsconfig.json

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "declaration": true,
        "module": "es6",
        "moduleResolution": "node",
        "target": "es5",
    }
}
当我尝试运行脚本时,我不断遇到以下错误:

./src/typescript/class/Car.ts 4:8模块解析失败时出错: 意外令牌(4:8)您可能需要适当的加载程序来处理 此文件类型无效

索引

import { Car } from './class/Car ';
let car= new Car ({
    color : 'blue'
});
汽车

export class Car {
    public color:string; /** here is where the error originates */

    constructor(config) { }
}

我相信您对
/\.tsx$/
测试与
.ts
扩展不匹配,应该更改为
/\.tsx?$/
@MattMcCutchen已经尝试过了。没有修复…您的tsconfig.json是什么?@PlayMa256处于编辑状态。:)