LoginSignup
6
6

More than 3 years have passed since last update.

Typescript + Webpackのビルドで、TypeScript emitted no output for

Last updated at Posted at 2019-07-30

Webpack+TypeScrptでビルドしたら、以下のエラーが出ました。

ERROR in ./src/javascript/types/index.d.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /var/www/src/javascript/types/file-loader.d.ts.
    at makeSourceMapAndFinish (/var/www/node_modules/ts-loader/dist/index.js:78:15)
    at successLoader (/var/www/node_modules/ts-loader/dist/index.js:68:9)
    at Object.loader (/var/www/node_modules/ts-loader/dist/index.js:22:12)
 @ multi ./src/javascript/config/Routes.tsx ./src/javascript/containers/components/Footer.tsx ./src/javascript/containers/components/forms/TextInput.tsx ./src/javascript/containers/components/Header.tsx ./src/javascript/containers/pages/SignIn.tsx ./src/javascript/index.tsx ./src/javascript/modules/i18n.ts ./src/javascript/types/index.d.ts app[7]

結論

webpackのentryにdeclareファイル(*.d.ts)が含まれていた為。

状況

どんな感じだったかというと、declareファイルを/src/javascript/types/index.d.tsに配置していて、Webpackのビルド対象になっていました。

wepack.config.js

const utils = require('./utils')

module.exports = {
  entry: utils.entryPaths(),
  output: {
    path: `./dist`,
    filename: '[name].js'
  },

utils.js

exports.entryPaths = () => {
  const jses = getFiles(`src/javascript/**/*.{ts,tsx}`)
  return { 'app': jses }
}

const getFiles = (path, options={}) => {
    return glob.sync(path, options).map((file) => {
        return file
    })
}

修正後

/src/javascript/types/index.d.ts -> /src/types/index.d.tsに移動して、tsconfig.jsonを以下のように修正しました。
(webpackのentryから外すけど、tsconfigの対象にする感じ。)

tsconfig.json

{
  "compilerOptions": {
    〜〜〜 省略 〜〜〜
    "typeRoots": ["src/types", "node_modules/@types"]
  },
  "include": [
    "src/**/*",
  ]
}
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6