question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ts-loader with Typescript 4.5 beta: "Error: TypeScript emitted no output for .../index.mts"

See original GitHub issue

Anyone have luck webpack-5-ing with the new .mts extension? I’m able to output from tsc -p . fine, but through webpack I’m getting “Error: TypeScript emitted no output for …/index.mts”.

Thanks!

    resolve: {
      // Add `.ts` and `.tsx` as a resolvable extension.
      extensions: [".mts", ".ts", ".tsx", ".js"]
    },
    module: {
      rules: [
        {
            test: /(\.mts$)|(\.tsx?$)/,
            use: [
                {
                    loader: 'ts-loader',
                    options: {
                        //transpileOnly: true
                        compilerOptions: {
                            noEmit: false
                        }
                    }
                }
            ]
        }
      ]
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:47 (24 by maintainers)

github_iconTop GitHub Comments

3reactions
andrewbranchcommented, Oct 15, 2021

@alexander-akait I put up a super simple repro showing that .js resolution to .ts doesn’t work, but haven’t had time to start seeing how ts-loader could be involved here. Honestly my expectation was that this would not work; I’m not super familiar with how ts-loader contributes to Webpack’s resolution, but my impression was that this would be a Webpack-level thing, not a ts-loader thing. https://github.com/andrewbranch/nodenext-webpack

2reactions
andrewbranchcommented, Oct 14, 2021

@alexander-akait the issue is that in the new TypeScript module resolution modes, users must write import "./foo.js" even though on disk, the colocated file is ./foo.ts. This is because TypeScript expects TS code to be compiled to JS with these import paths unchanged, that way the output JS will resolve correctly at runtime. But this breaks the expectations of bundlers like Webpack, which does module resolution before a 1:1 TS→JS compilation happens. So the correct specifier for Webpack would be import "./foo.ts" but TypeScript doesn’t allow that. The correct specifier for TypeScript is import "./foo.js" but Webpack can’t resolve that by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript emitted no output for '/path/to/file.ts' - Stack Overflow
I can reproduce this error if the application tries to import a TypeScript source file from the library (i.e., from the lib subdirectory)....
Read more >
typescript emitted no output for - You.com | The search engine you ...
Hi, using your module with webpack, ts-loader 1.3 and typescript 2.1.4: modulesModuleBuildError: Module build failed: Error: Typescript emitted no output for ...
Read more >
ts-loader - npm
Start using ts-loader in your project by running `npm i ts-loader`. ... ts-loader. This is the TypeScript loader for webpack.
Read more >
Announcing TypeScript 4.5 Beta - Microsoft Developer Blogs
ts file is compiled as an ES module, ECMAScript import / export syntax is left alone in the .js output; when it's compiled...
Read more >
webpack/webpack - Gitter
src/app.ts Module build failed: Error: Typescript emitted no output for ... /TypescriptFifthApp/node_modules/ts-loader/index.js:456:15) @ multi main.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found