s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 181 forks source link

TypeScript cannot find module "awesome-typescript-loader" when using ES2015 modules in tsconfig #486

Open Daiz opened 7 years ago

Daiz commented 7 years ago

I decided that I wanted to convert my webpack.config.js into webpack.config.ts and ran into the following issue:

image

It didn't work out-of-the-box, and it didn't work even after adding a direct reference to the index.d.ts that the typings in ATS's package.json points to.

Running tsc also produces the following errors:

$ tsc
node_modules/awesome-typescript-loader/dist/interfaces.d.ts(1,21): error TS2307: Cannot find module 'typescript'.
node_modules/awesome-typescript-loader/dist/paths-plugin.d.ts(2,21): error TS2307: Cannot find module 'typescript'.
webpack.config.ts(3,31): error TS2307: Cannot find module 'awesome-typescript-loader'.

(The typescript module is installed locally for the project.)

In summary, something seems to be going wrong with the typings for ATS that lead to these issues. I couldn't manage to find any quick way to fix it with a cursory glance, so for the time being I just have a declare module "awesome-typescript-loader"; in a personal .d.ts file.

Daiz commented 7 years ago

Right after posting I discovered that changing "module": "es2015" to "module": "commonjs" in the project's tsconfig.json makes these issues go away. It's not really an option for the whole project though since it would mean losing out Webpack 2's ES2015 module tree shaking and it's really just an issue for the webpack config file, so it would be ideal for ATS typings to just work with "module": "es2015" in tsconfig.json too.

myknbani commented 7 years ago

I can confirm this issue. webpack.config.ts does not work, but webpack.config.js does.

Aside from an extra allowJs in tsconfig, not really a deal-breaker.