ts-loader icon indicating copy to clipboard operation
ts-loader copied to clipboard

Module parse failed: Unexpected token

Open chirastefan opened this issue 3 years ago • 2 comments
trafficstars

Expected Behaviour

This might be related to ts-loader.

Actual Behaviour

Screen Shot 2022-03-30 at 17 08 50

Steps to Reproduce the Problem

module.exports = {
  context: resolve(__dirname, '../src'),
  plugins: [ ... ],
  resolve: {
    modules: ['node_modules', 'src'],
    extensions: ['.js', '.jsx', '.ts', '.tsx']
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [
                [
                  '@babel/preset-env',
                  {
                    targets: 'last 3 versions'
                  }
                ],
                '@babel/preset-react'
              ]
            }
          }
        ]
      },
      {
        test: /\.(ts|tsx)$/,
        // exclude: '/node_modules/',
        exclude: path.resolve(__dirname, '../node_modules/'),
        use: {
          loader: 'ts-loader',
          options: {
            presets: [
              // [
              //   '@babel/preset-env',
              //   {
              //     targets: 'last 3 versions'
              //   }
              // ],
              // '@babel/preset-react',
              //'@babel/preset-react',
              //'@babel/preset-typescript'
            ],
            // configFile: path.resolve(__dirname, 'tsconfig.json'),
            // allowTsInNodeModules: true,
            transpileOnly: true
          }
        }
      }
    ]
  }
};

tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "declaration": true
  },
  "include": ["./src/**/*.ts", "./src/**/*.tsx"],
  "exclude": ["./node_modules", "./dist", "./config"]
}

Versions

ts-loader: ^8.2.0 webpack: 4.46.0 typescript: ^4.6.3

chirastefan avatar Mar 30 '22 14:03 chirastefan

@chirastefan Did you find a fix to this? I'm still stuck on this.

lazyvab avatar Jun 10 '22 11:06 lazyvab

nope

chirastefan avatar Jul 14 '22 08:07 chirastefan