Serge Esmanovich Serge Esmanovich -4 years ago 199
TypeScript Question

webpack doesn't see files

tsconfig:

{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": true
},
"files": [
"sample2-inject/app.ts"
],
"exclude": [
]
}


webpack.config.js:

var path = require('path');
module.exports = {
entry: path.resolve("./sample2-inject/app.ts"),
output: {
path: path.resolve("./dist"),
filename: "bundle.js",
library: "home"
},
resolve: {
extensions: [".webpack.js", ".web.js", ".ts", ".js"]
},
module: {
loaders: [
{loader: "ts-loader"}
]
},
watch: true,
devtool: "eval"
};


app.ts:

import "es6-shim";
import "reflect-metadata";
import {Container} from "typedi";


Errors:


[0] ./~/typedi/index.js 528 bytes {0} [built] [failed] [1 error] [1]
./~/es6-shim/es6-shim.js 533 bytes {0} [built] [failed] [1 error] [2]
./~/reflect-metadata/Reflect.js 540 bytes {0} [built] [failed] [1
error]

ERROR in ./~/reflect-metadata/Reflect.js Module build failed: Error:
Could not find file:
'/home/sesmanovich/www/JQueryPlugins/node_modules/reflect-metadata/Reflect.js'.
at getValidSourceFile
(/usr/local/lib/node_modules/typescript/lib/typescript.js:81080:23) at
Object.getEmitOutput
(/usr/local/lib/node_modules/typescript/lib/typescript.js:81446:30) at
getEmit
(/home/sesmanovich/www/JQueryPlugins/node_modules/ts-loader/dist/index.js:99:43)
at Object.loader
(/home/sesmanovich/www/JQueryPlugins/node_modules/ts-loader/dist/index.js:27:11)
@ ./sample2-inject/app.ts 4:0-27

Answer Source

From your webpack config:

    loaders: [
        {loader: "ts-loader"}
    ]

Is wrong. You should only use ts-loader for ts/tsx files.

loaders: [ // loaders will work with webpack 1 or 2; but will be renamed "rules" in future
  // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
  { test: /\.tsx?$/, loader: 'ts-loader' }
]

More

See readme : https://github.com/TypeStrong/ts-loader#configuration

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download