TypeScript检查前端模板文件

时间:2016-10-21 10:00:46

标签: typescript webpack handlebars.js

我是TypeScript的新手,非常喜欢它。 目前,使用Webpack + TypeScript + Handlebars并获得以下错误消息:

ERROR in ./src/apps/router/routes.ts
(6,26): error TS2307: Cannot find module '../templates/homeTpl.handlebars'.

ERROR in ./src/apps/router/routes.ts
(9,27): error TS2307: Cannot find module '../templates/aboutTpl.handlebars'.

我在package.json和"@types/handlebars": "^4.0.31"中安装了"handlebars": "registry:dt/handlebars#4.0.5+20160804082238",位于typings.json

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es5",
    "removeComments": true
  },
"include": [
    "src/**/*"
  ],
"exclude": [
    "node_modules"
  ]
}

我的webpack.config.js也包括

...

  resolve: {
    // Add '.ts' and '.tsx' as resolvable extensions.
    extensions: ["", ".ts", ".js"]
  },

  module: {
    loaders: [{
      test: /\.ts?$/,
      exclude: /node_modules/,
      loader: 'ts-loader'
    }, {
      test: /\.handlebars?$/i,
      loader: 'handlebars-loader'
    }]
  }
...

我尝试了很多但却无法弄清楚出了什么问题! https://github.com/Protocore-UI/protocore-typescript-edition。 好吧,当我排除TypeScript并使用ES6和Webpack时,它的工作正常https://github.com/Protocore-UI/protocore-webpack-edition

1 个答案:

答案 0 :(得分:0)

我通过添加require声明来解决问题:

O(N^2)

访问https://github.com/Microsoft/TypeScript/issues/5151了解详情