TypeStrong / TypeStrong/ts-loader

Module parse failed: Unexpected token

Open
#1,442 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported webpack build using the inline webpack configuration, tsconfig.json, and the listed ts-loader, webpack, and TypeScript versions. Start from the module-parse error and inspect which loader rule handles the failing file; done means identifying the configuration or loader mismatch and confirming the corrected build behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.