Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-loader can't load Typescript with any version > 5.0.4 #1635

Open
RationalG opened this issue Oct 13, 2023 · 4 comments
Open

ts-loader can't load Typescript with any version > 5.0.4 #1635

RationalG opened this issue Oct 13, 2023 · 4 comments

Comments

@RationalG
Copy link

RationalG commented Oct 13, 2023

This is the webpack config file I am using :

var webpack = require('webpack');
var path = require('path');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: './src/index.ts',
  target: 'node',
  output: {
    filename: 'app.js',
    libraryTarget: 'commonjs2',
    path: path.resolve(__dirname, 'dist'),
  },
  devtool: 'source-map',
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin()],
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  module: {
    rules: [
      // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
      { test: /\.tsx?$/, loader: 'ts-loader' },
    ],
  },
};

Expected Behaviour

Running webpack --config ./webpack.config.js with any Typescript version > 5.0.4 should pass

Actual Behaviour

This is what I get when I try running webpack with any Typescript version > 5.0.4 :

Error: Could not load TypeScript. Try installing with yarn add typescript or npm install typescript. If TypeScript is installed globally, try using yarn link typescript or npm link typescript.

However, this works with any version <= 5.0.4, so, I am not sure what would be the workaround for this.

@frg100
Copy link

frg100 commented Oct 27, 2023

I've been banging my head against the wall - thanks for reporting this! I'm having the same issue. Downgrading to 5.0.4 worked!

@AlekhyaYalla
Copy link

Any fix here for typescript >5.0.4. I'm getting below error for the typescript 5.2.2

\tsconfig.webpack.json(12,5)
ERR!         TS6266: Option 'listFilesOnly' can only be specified on command line.
ERR!   Module build failed (from ../../../.store/ts-loader@8.4.0-d2229b2707be7f1686e4/node_modules/ts-loader/index.js):
ERR!   Error: error while parsing tsconfig.json
ERR!       at Object.loader (node-modules\ts-loader@8.4.0-d2229b2707be7f1686e4\node_modules\ts-loader\dist\index.js:18:18)

@johnnyreilly
Copy link
Member

It looks like you're using an old version of ts-loader; 8.4.

Also it looks like your code may have an issue?

TS6266: Option 'listFilesOnly' can only be specified on command line.'

@derjanb
Copy link

derjanb commented Jan 16, 2024

This happens here when "esm" is used, which is incompatible with Typescript's use of the ?? operator since 5.0.5+

standard-things/esm#866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants