Webpack Typescript Неожиданный токен для всего, что связано с машинописью - PullRequest
0 голосов
/ 26 марта 2020

У меня проблема с компиляцией кодовой базы машинописного текста 3.8 с Webpack 4. Всякий раз, когда я собираюсь, я получаю сообщение об ошибке в каждом модуле с указанием неожиданного токена (строка: столбец). Он всегда ссылается на ключевое слово машинописи, например, на интерфейс. Я использую webpack cli с версией webpack, которая поставляется вместе с create-реагирующим приложением.

Например, ошибка

ERROR in ./src/components/WaitOrder/EmailCaptureModal.tsx 9:7
Module parse failed: Unexpected token (9:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import './emailCaptureModal.scss';
| 
> export interface EmailCaptureModalProps {
|   consumer: IConsumerStore;
|   title?: string;

Конфигурация Webpack

const path = require('path');
const nodeExternals = require('webpack-node-externals');
const package = require('./package.json');
const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  entry: {
    index: path.resolve('./src/index.ts')
  },
  devtool: 'source-map',
  resolve: {
    extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
  },
  output: {
    libraryTarget: 'commonjs2',
    library: 'library-name',
    path: path.join(__dirname, 'lib'),
    filename: '[name].js'
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)?$/,
        exclude: [
          path.resolve(__dirname, '/node_modules'),
          /^(?!.*\.test\.(ts|tsx)$).*\.(ts|tsx)$/
        ],
        use: ['ts-loader']
      }
    ]
  },
  externals: [
    nodeExternals({
      whitelist: Object.keys(package.dependencies)
    })
  ],
  // The SCSS files have variables in them so we want to leave it up
  // to the consumer of this library to compile them
  plugins: [
    new CopyPlugin([{ from: 'src/styles/*', to: 'styles', flatten: true }])
  ]
};

Tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "outDir": "lib",
    "sourceMap": true
  },
  "include": ["src"]
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...