【发布时间】:2017-08-23 03:46:30
【问题描述】:
我尝试在webpack 2 中使用typescript 2.2.2 和babel 加载程序并排除node_modules,但是当尝试webpack 命令时仍然会从node_modules 中的angular 4.0.0 得到错误。
webpack.congfig.js:
var path = require('path');
var webpack = require('webpack');
var PROD = true;
module.exports = {
entry: path.join(__dirname, 'ng2', 'src','index.js'),
output: {
path: path.join(__dirname, 'ng2', 'dist'),
filename: 'vendorNG2.js'
},
devtool: 'eval',
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
watch: true,
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: [/node_modules/],
},
{
test: /\.js$/,
exclude: [/node_modules/],
use: {
loader: "babel-loader?cacheDirectory=true",
options: {
presets: ['es2015']
}
}
},
]
},
plugins: PROD ? [
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false }
})
] : []
}
在 webpack --progress 命令之后:
...
ERROR in /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts
(13,17): error TS2693: 'Map' only refers to a type, but is being used as a value here.
ERROR in /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts
(14,17): error TS2693: 'Set' only refers to a type, but is being used as a value here.
ERROR in ./ng2/src/app/main.ts
(19,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
您可以看到来自 node_modules 的错误。
tsconfig.json v1:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true
}
}
tsconfig.json v2:
{
"compilerOptions": {
"outDir": "./ng2/dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"type":[],
"allowJs": true
},
"exclude": [
"node_modules"
]
}
v2 错误:
ERROR in /home/user/Projects/project/front/admin/tsconfig.json
error TS5023: Unknown compiler option 'type'.
@ ./ng2/src/index.js 8:0-21
ERROR in ./ng2/src/app/main.ts
Module build failed: error while parsing tsconfig.json
@ ./ng2/src/index.js 8:0-21
tsconfig.js v3 add ("experimentalDecorators": true) 一些错误消失了:
{
"compilerOptions": {
"outDir": "./ng2/dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"experimentalDecorators": true,
"allowJs": true
},
"exclude": [
"node_modules"
]
}
v3 错误:
... /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts 中的错误 (13,17): 错误 TS2693: 'Map' 仅指一种类型,但在此处用作值。
/home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts 中的错误 (14,17): 错误 TS2693: 'Set' 仅指一种类型,但在此处用作值。
【问题讨论】:
-
你的
tsconfig是什么样的? -
查看更新后的帖子
-
您是否尝试将
experimentalDecorators: true添加到您的tsconfig中? - 如果它们不起作用,请尝试添加"types": [] -
试试
"types:[]"- 不是"type"
标签: angular typescript webpack