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";
错误:
[0] ./~/typedi/index.js 528字节{0} [内置] [失败] [1错误] [1] ./~/es6-shim/es6-shim.js 533字节{0} [内置] [失败] [1错误] [2] ./~/reflect-metadata/Reflect.js 540字节{0} [建立] [失败] [1 错误]
>错误在./~/reflect-metadata/Reflect.js模块构建失败:错误: 找不到文件: ' /home/sesmanovich/www/JQueryPlugins/node_modules/reflect-metadata/Reflect.js' ;. 在getValidSourceFile (/usr/local/lib/node_modules/typescript/lib/typescript.js:81080:23)at at Object.getEmitOutput (/usr/local/lib/node_modules/typescript/lib/typescript.js:81446:30)at at getEmit (/home/sesmanovich/www/JQueryPlugins/node_modules/ts-loader/dist/index.js:99:43) 在Object.loader (/home/sesmanovich/www/JQueryPlugins/node_modules/ts-loader/dist/index.js:27:11) @ ./sample2-inject/app.ts 4:0-27
答案 0 :(得分:1)
从您的webpack配置:
loaders: [
{loader: "ts-loader"}
]
错了。您只应将ts-loader
用于ts/tsx
个文件。
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' }
]
请参阅自述文件:https://github.com/TypeStrong/ts-loader#configuration