我想用webpack 2和typescript 2配置我的角2,并且遇到重复的标识符错误。我已经搜索了多种解决方案,迄今为止没有任何帮助。重复的标识符错误 - Angular 2和Typescript 2的Webpack 2配置
错误:
typings\globals\core-js\index.d.ts
`Duplicate identifier 'PropertyKey'
typings\globals\core-js\index.d.ts
`Duplicate identifier 'Promise'
typings\globals\es6-promise\index.d.ts
`Duplicate identifier 'Promise'
typings\globals\es6-shim\index.d.ts
`Duplicate identifier 'PropertyKey'
我试着加入环境依赖于我的typings.json文件没有成功,并且还试图彻底清除globalDependencies和刚刚离开ambientDependencies:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
"es6-collections": "registry:dt/es6-collections#0.5.1+20160316155526",
"es6-promise": "registry:dt/es6-promise#0.0.0+20160614011821",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046"
},
"ambientDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160215162030"
}
}
我试过在tsconfig.json文件中排除整个类型目录,但是导致其他错误如下:
node_modules\@angular\platform-browser\src\facade\collection.d.ts:8:8
Cannot find name 'Map'.
我现在tsconfig.json低于:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true
},
"exclude":[
"node_modules",
"typings/main",
"typings/main.d.ts"
],
"awesomeTypescriptLoaderOptions":{
"useWebpackText":true
}
}
我也尝试添加下列到tsconfig.json的排除阵列:
"browser"
"browser.d.ts"
最后,我webpack.config.js低于:
var webpack = require('webpack');
var HtmlWebPackPlugin = require('html-webpack-plugin');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
context: path.resolve('app'),
entry: {
'app':'./main.ts'
},
output:{
path: path.resolve('dist'),
publicPath:'/',
filename: 'bundle.js'
},
resolve:{
extensions:['', '.js', '.ts']
},
devtool:'module-inline-source-map',
watch:true,
devServer: {
historyApiFallback: true,
stats: 'minimal'
},
module:{
loaders: [
{
test:/\.ts$/,
exclude:/node_modules/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: "html"
},
{
test: /\.css$/,
exclude: path.resolve('app'),
loader: ExtractTextPlugin.extract({fallbackLoader: 'style-loader', loader: 'css-loader'})
},
{
test: /\.css$/,
include: path.resolve('app'),
loader: 'raw'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file?name=fonts/[name].[hash].[ext]?'
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader:'file'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader:'url?limit=10000&mimetype=application/octet-stream'
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader:'url?limit=10000&mimetype=image/svg+xml'
}
]
},
plugins: [
new ExtractTextPlugin("styles.css"),
new HtmlWebPackPlugin({
template: path.resolve('app/index.html')
}),
new webpack.ProvidePlugin({
$: "jquery",
jquery:"jquery",
jQuery:"jquery",
"windows.jQuery":"jquery",
"window.Tether":'tether'
})
]
}
- 角2版本:2.0.0-rc.6
- 打字稿版本:2.0.2
- 的WebPack版本:2.1.0-beta.20
如果任何人有任何这见解,我会感激你的帮助。
谢谢!
只是一个更新以显示更改后Dave V提供了答案:在分型根
globals/es6-promise
globals/es6-shim
browser
index.d.ts:
的follwing的文件夹是从分型目录中删除删除了以下参考文件:
/// <reference path="globals/es6-promise/index.d.ts" />
/// <reference path="globals/es6-shim/index.d.ts" />
此外,我添加了"typings/browser.d.ts"
到tsconfig.json排除阵列,因为它是引用es6-shim
内browser/ambient
:
"exclude":[
"node_modules",
"typings/main",
"typings/main.d.ts",
"typings/browser.d.ts"
]
好的,但我会去哪里排除其中的一个,因为tsconfig。json似乎并不尊重以下内容,仍然存在以下问题:''排除“:[ ”typings/globals/es6-promise“, ”typings/globals/es6-shim“, ”typings/browser/ambient/es6-shim“ ”node_modules“, ”typings/main“, ”typings/main.d.ts“ ]' – AKN
您需要将其从'typings.json'文件中删除,以便它不会安装并将它从index.d.ts(如果这就是所谓的main.d.ts)中删除,则将其从main.d.ts文件中删除。 –
谢谢!修复了我所看到的错误,我将编辑我的帖子以根据您的解决方案显示我所做的工作,所以如果有人遇到同一问题,他们可以看到更改。 – AKN