Webpack cant resolve TypeScript modules

前端 未结 4 1384
耶瑟儿~
耶瑟儿~ 2020-12-14 05:43

I build a relay small webpack and typescript demo to play with. If i run webpack with the webpack.config.js i get this error:

ERROR in ./js/app.ts
Module not         


        
相关标签:
4条回答
  • 2020-12-14 06:03

    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'
    
    0 讨论(0)
  • 2020-12-14 06:04

    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...

    0 讨论(0)
  • 2020-12-14 06:20

    I'm using tsconfig instead of webpack which also compiles the submodule to a bundle (index.js).

    The issue for me was that I had forgotten to compile the submodule (ie run tsc to generate index.js) before referencing it from outside.

    0 讨论(0)
  • 2020-12-14 06:24

    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']
    }
    
    0 讨论(0)
提交回复
热议问题