ts-loader: Fails when processing .js files

I’m trying to drop typescript into an existing project. In my webpack config I have:

extensions: ['', '.js', '.jsx', '.json']

And my loaders:

loaders: [ 'react-hot-loader', 'babel-loader', 'ts-loader' ]

However, when I try to build, I now get:

ERROR in ./app/main.js
Module build failed: Error: Could not find file: './app/main.js'.
    at getValidSourceFile (node_modules/typescript/lib/typescript.js:43586:23)
    at Object.getEmitOutput (node_modules/typescript/lib/typescript.js:46680:30)
    at Object.loader (node_modules/ts-loader/index.js:408:34)
@ multi app

The only thing i’ve changed is adding ts-loader to the loader list. Is this because my main.js file doesn’t have a .ts or .jsx extension?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 10
  • Comments: 22 (13 by maintainers)

Most upvoted comments

As a pointer for others needing to compile js files. It seems https://github.com/s-panferov/awesome-typescript-loader is handling this as expected.

Still doesn’t work. Any plans to fix it?

Confirming that this is still an issue even with TypeScript 1.9.0-dev.20160220. I’ve basically just swapped babel as a loader in my Webpack config with ts-loader; setting it to consume .ts instead (and renaming my entry to .ts) fixes the problem.

We are looking to transition our js codebase to ts in gradual steps. For this, we want to use ts-loader to compile our js files.

What needs to be done to make this work (with allowJs flag set)?

Any pointers? Maybe I could take a look.

Thank you

Sorry wasn’t clear enough, I have this working with ts-loader, but it was claimed above that awesome-typescript-loader is “handling this as expected”. I do have allowJs set, awesome-typescript-loader doesn’t seem to have an entryFileIsJs option set.

It does but at present you need to use the entryFileIsJs option set. (This requirement will be dropped as part of the V3 release.)

We have a test in our test pack that covers this in case you’re curious

Yea, TypeScript requires a file extension of .ts or .tsx (or .d.ts for definition files). I believe there is work going on to expand support for regular JavaScript in the future but for now you’ll need to limit the use of ts-loader to only files with the TypeScript extensions. That doesn’t mean you can’t continue to use normal .js files in your webpack build. You can set .js files to go through babel and .ts files to go through ts-loader and then babel.