Webpack cant resolve TypeScript modules

余生颓废 提交于 2019-11-30 04:33:16

Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts. Don't forget to add the default values as well, otherwise most modules will break because they rely on the fact that the .js extension is automatically used.

resolve: {
    extensions: ['.ts', '.js', '.json']
}

Tried all the suggestions above and it still didn't work.

Ended up being the tiniest detail:

In webpack.js, instead of:

resolve: {
  extensions: ['.tsx', '.ts', '.js']
},

The ordering should be:

resolve: {
  extensions: ['.ts', '.tsx', '.js']
},

Don't know why this is necessary, and to be quite honest, I'm beyond caring at this point...

Leaving this here for posterity, but I had this exact same issue and my problem was that my entry path was not relative but absolute. I changed entry from:

entry: 'entry.ts'

to

entry: './entry.ts'

You use in tsconfig.js - "module": "commonjs", but in your code you use es6 module. I think, you should change "module": "ES6".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!