使用TypeScript的Babel-loader和Webpack语法错误

时间:2018-11-12 16:49:09

标签: angularjs typescript webpack babel babel-loader

我将Angular 5,Webpack和Babel-loader用于我的Microsoft加载项项目。但是,由于冒号,Babel尝试编译我的项目时,出现语法错误。我尝试了Google / Stackoverflow上的许多其他选项,但似乎无法解决此错误。

错误消息:

ERROR in ./src/app/services/data.service.ts
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: C:/Users/lofo/Projects/word-add- 
in/src/app/services/data.service.ts: Unexpected token, expected , (17:22)

  15 | export class DataService {
  16 |
> 17 |   constructor(private http: HttpClient) { }
     |                       ^
  18 |
  19 |   // getUsers(): Observable<IUser> {
  20 |   //   return this.http.get<IUser>(apiUrl + '/users');

 @ ./src/app/app.module.ts 30:12-51
 @ ./src/index.ts
 @ multi (webpack)-dev-server/client?https://localhost:3000 ./src/index.ts
Child html-webpack-plugin for "function-file\function-file.html":
     1 asset
    Entrypoint undefined = function-file/function-file.html
       1 module
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
       1 module
i 「wdm」: Failed to compile.

Webpack.config:

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: {
    polyfill: 'babel-polyfill',
    app: './src/index.ts',
    'function-file': './function-file/function-file.ts'
},

resolve: {

    extensions: ['.ts', '.tsx', '.html', '.js']

},
module: {
    rules: [
        {
            test: /\.ts$/,
            exclude: /node_modules/,
            use: 'babel-loader'
        },
        {
            test: /\.html$/,
            exclude: /node_modules/,
            use: 'html-loader'
        },
        {
            test: /\.(png|jpg|jpeg|gif)$/,
            use: 'file-loader'
        }
    ]
},
plugins: [
    new HtmlWebpackPlugin({
        template: './index.html',
        chunks: ['polyfill', 'app']
    }),
    new HtmlWebpackPlugin({
        template: './function-file/function-file.html',
        filename: 'function-file/function-file.html',
        chunks: ['function-file']
    })
]
};

.babelrc:

{
"presets": [
    "env"
],
"plugins": [
    "transform-decorators-legacy",
    "transform-class-properties"
]
}

0 个答案:

没有答案