Ниже кода TypeScript (это означает, что статические поля класса и другие функции TypeScript доступны) успешно построен с помощью Webpack:
export default class ConfigRepresentative {
constructor() {
console.log('ok');
}
}
Сбои (то же самое, если удалить private
и static
):
export default class ConfigRepresentative {
private static ownInstanceHasBeenCreated: boolean = false;
constructor() {
console.log('ok');
}
}
Ошибка:
ERROR in ./TypeScriptSource/index.ts 7:10
Module parse failed: Unexpected token (7:10)
You may need an appropriate loader to handle this file type.
| export default class ConfigRepresentative {
|
> private static ownInstanceHasBeenCreated: boolean = false;
|
| constructor() {
webpack.config.js
module.exports = {
entry: './TypeScriptSource/index.ts',
output: {
filename: 'index.js',
path: __dirname,
libraryTarget: 'umd'
},
target: 'node',
mode: 'production',
watch: true,
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.ts', '.js']
}
};
Чтобы сэкономить ваше время при воспроизведении этой проблемы, я прикрепил файлы souse. error.zip