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

Error: Unable to use specified module loaders for ".ts". #1993

Closed
Stanzilla opened this issue Oct 28, 2020 · 11 comments · Fixed by #2282
Closed

Error: Unable to use specified module loaders for ".ts". #1993

Stanzilla opened this issue Oct 28, 2020 · 11 comments · Fixed by #2282

Comments

@Stanzilla
Copy link

Describe the bug

Hey there, just updated to wp-cli 4.1 an webpack 5.3 and getting the following error

What is the current behavior?

> webpack --mode development

[webpack-cli] Error: Unable to use specified module loaders for ".ts".
    at Object.exports.prepare (/home/stan/projects/work/vscode-core/node_modules/rechoir/index.js:58:11)
    at requireConfig (/home/stan/projects/work/vscode-core/node_modules/webpack-cli/lib/groups/ConfigGroup.js:70:17)
    at Array.map (<anonymous>)
    at resolveConfigFiles (/home/stan/projects/work/vscode-core/node_modules/webpack-cli/lib/groups/ConfigGroup.js:124:40)
    at module.exports (/home/stan/projects/work/vscode-core/node_modules/webpack-cli/lib/groups/ConfigGroup.js:233:11)
    at WebpackCLI._baseResolver (/home/stan/projects/work/vscode-core/node_modules/webpack-cli/lib/webpack-cli.js:68:38)
    at /home/stan/projects/work/vscode-core/node_modules/webpack-cli/lib/webpack-cli.js:198:30
    at async WebpackCLI.runOptionGroups (/home/stan/projects/work/vscode-core/node_modules/webpack-cli/lib/webpack-cli.js:197:9) {
  failures: [
    { moduleName: 'ts-node/register', module: null, error: [Error] },
    {
      moduleName: 'typescript-node/register',
      module: null,
      error: [Error]
    },
    { moduleName: 'typescript-register', module: null, error: [Error] },
    { moduleName: 'typescript-require', module: null, error: [Error] },
    { moduleName: 'sucrase/register/ts', module: null, error: [Error] },
    { moduleName: '@babel/register', module: null, error: [Error] }
  ]
}

To Reproduce

My config:

// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');

const config = {
    target: 'node',

    entry: './src/extension.ts',
    output: {
        filename: 'extension.js',
        libraryTarget: "commonjs2",
        devtoolModuleFilenameTemplate: "../[resource-path]",
    },
    devtool: 'source-map',
    externals: {
        vscode: "commonjs vscode"
    },
    resolve: {
        extensions: ['.ts', '.js']
    },
    module: {
        rules: [{
            test: /\.ts$/,
            exclude: /node_modules/,
            use: [{
                loader: 'ts-loader',
                options: {
                    compilerOptions: {
                        "module": "es6"
                    }
                }
            }]
        }]
    },
};

module.exports = config;

Steps to reproduce the behavior:

  1. webpack --mode development

Expected behavior

functioning build

Screenshots

Please paste the results of webpack-cli info here, and mention other relevant information

Additional context

@Stanzilla Stanzilla added the Bug label Oct 28, 2020
@alexander-akait
Copy link
Member

alexander-akait commented Oct 28, 2020

You need to install something from:

failures: [
    { moduleName: 'ts-node/register', module: null, error: [Error] },
    {
      moduleName: 'typescript-node/register',
      module: null,
      error: [Error]
    },
    { moduleName: 'typescript-register', module: null, error: [Error] },
    { moduleName: 'typescript-require', module: null, error: [Error] },
    { moduleName: 'sucrase/register/ts', module: null, error: [Error] },
    { moduleName: '@babel/register', module: null, error: [Error] }
  ]

Without it we can't covert ts to js

@alexander-akait
Copy link
Member

But I think we should improve the error message

@Stanzilla
Copy link
Author

It was ts-node indeed, but yeah, error message needs improvements :)

@anshumanv
Copy link
Member

will do, this err is coming from interpreting so maybe we can throw our own err if required packages are missing

@Stanzilla
Copy link
Author

Thank you!

@soulofmischief
Copy link

I am getting this exact issue for .babel.js files, it says I'm missing @babel/register but it's present in my node_modules.

failures: [
    { moduleName: '@babel/register', module: null, error: [Error] },
    { moduleName: 'babel-register', module: null, error: [Error] },
    { moduleName: 'babel-core/register', module: null, error: [Error] },
    { moduleName: 'babel/register', module: null, error: [Error] }
  ]
}

Any idea what could be causing this? It just started happening out of nowhere and none of my package versions have changed. I've reverted the project to its last known good state and still get this error.

@alexander-akait
Copy link
Member

You don't have @babel/register in node_modules no magic here

@soulofmischief
Copy link

soulofmischief commented Nov 1, 2020

@evilebottnawi @babel/register is in fact present in node_modules, or I wouldn't have posted the above comment. I stated above that it's present. Do you need a screenshot?

edit: I looked into it more tonight. @babel/core somehow got dropped off my dependencies list before the "last known good state" I was reverting to.

@babel/register was present, but not @babel/core, and this was causing the error claiming @babel/register was missing. Idk if webpack-cli is able to tell the difference, but in any case yes the error is misleading.

@anshumanv
Copy link
Member

Thanks for checking @soulofmischief, yes it will be improved today

@chrishaack422
Copy link

It was ts-node indeed, but yeah, error message needs improvements :)

you are right

@Taschenbuch
Copy link

Taschenbuch commented Mar 2, 2023

yeah, please improve the error message. I just ran into the same error and was very confused because ts-loader was installed. i heard of ts-node for the first time.

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

Successfully merging a pull request may close this issue.

6 participants