在tsconfig中映射路径后,Webpack无法构建

时间:2017-11-15 16:01:53

标签: typescript webpack

我尝试通过添加以下内容来映射我的tsconfig文件中的一些路径:

"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
  "@models/*": [ "ClientApp/app/models/*" ] // This mapping is relative to "baseUrl"
},

但是当我构建我的项目时,webpack会抛出很多错误并且不构建。我的错误日志如下所示:

[at-loader] Using typescript@2.5.3 from typescript and "tsconfig.json" from C:\Users\av427g\Documents\Visual Studio 2017\Projects\Sankini\Sankini\Sankini/tsconfig.json.


[at-loader] Using typescript@2.5.3 from typescript and "tsconfig.json" from C:\Users\av427g\Documents\Visual Studio 2017\Projects\Sankini\Sankini\Sankini/tsconfig.json.


[at-loader] Checking started in a separate process...

[at-loader] Ok, 0.214 sec.

[at-loader] Checking started in a separate process...

[at-loader] Ok, 0.185 sec.
Hash: 355ef8ecfe14a53528d4c53ed6ce1f3ab6fc27fb
Version: webpack 2.7.0
Child
    Hash: 355ef8ecfe14a53528d4
    Time: 22357ms
                 Asset     Size  Chunks                    Chunk Names
        main-client.js   907 kB       0  [emitted]  [big]  main-client
    main-client.js.map  1.03 MB       0  [emitted]         main-client

    ERROR in ./ClientApp/app/components/home/head/head-edit.component.ts
Module not found : error : Can't resolve '@models/HomeHeadDataModel' in 'C:\Users\av427g\Documents\Visual Studio 2017\Projects\Sankini\Sankini\Sankini\ClientApp\app\components\home\head'
     @ ./ClientApp/app/components/home/head/head-edit.component.ts 13:0-62
     @ ./ClientApp/app/components/home/home.module.ts
     @ ./ClientApp/app/app.module.shared.ts
     @ ./ClientApp/app/app.module.browser.ts
     @ ./ClientApp/boot.browser.ts

    ERROR in ./ClientApp/app/components/home/team/team-edit.component.ts
Module not found : error : Can't resolve '@models/HomeTeamDataModel' in 'C:\Users\av427g\Documents\Visual Studio 2017\Projects\Sankini\Sankini\Sankini\ClientApp\app\components\home\team'
     @ ./ClientApp/app/components/home/team/team-edit.component.ts 13:0-62
     @ ./ClientApp/app/components/home/home.module.ts
     @ ./ClientApp/app/app.module.shared.ts
     @ ./ClientApp/app/app.module.browser.ts
     @ ./ClientApp/boot.browser.ts
............

我不知道为什么这样做。如您所见,at-loader似乎加载了正确的tsconfig.json文件,而我的intellisense没有抛出任何错误。只有在建设

1 个答案:

答案 0 :(得分:2)

我希望现在还为时不晚,我遇到了同样的问题,我浪费了很多时间寻找解决方案。这里的问题是webpack不知道你的@models模块解析。你应该做的是将它添加到你的webpack配置:

  Feature file :
    Scenario Outline: Verify content of my probblem1


Scenario,                       Title1, Title2, Title3, Title4, Title5
Verify content of my probblem1, Text1,  Text2,  Text3,  Text4,  Text5,
Verify content of my probblem2, Text1,  Text2,  Text3,  Text4,  Text5,