2016-10-31 44 views
1

我已經遍尋全面解決了這個問題,並沒有任何運氣。我試圖找出爲什麼我收到以下錯誤:React沒有任何導出成員'道具'

ERROR in ~/node_modules/@types/react-router/lib/applyRouterMiddleware.d.ts 
(4,43): error TS2305: Module ‘」~/node_modules/react/react".export=' has no exported member 'Props'. 

有數以百計的這些,涉及到幾乎所有的@types定義文件引用不導出屬性。

我在這裏使用webpack進行構建過程。這裏是webpack.config.js

module.exports = { 
    target: 'node', 
    devtool: 'source-map', 
    devServer: { historyApiFallback: true }, 
    context: root(), 
    entry: './src/index.tsx', 

    resolve: { 
    extensions: [ '', '.js', '.ts', '.tsx', '.scss', '.css' ], 
    root: root('src'), 
    alias: { 
     //inject environment variables via aliases 
     conf: isProd() ? './conf/production.js' : './conf/development.js', 
    }, 
    }, 

    output: { 
    filename: 'bundle.js', //the output js file 
    path: root('dist'), //build directory 
    libraryTarget: 'umd', 
    }, 

    externals: { 
    fs: 'fs', 
    winston: 'winston', 
    system: '{}', 
    file: '{}', 
    }, 

    module: { 
    loaders: [ 
     { 
     test: /\.tsx?$/, 
     loader: 'ts-loader', 
     }, 
     { 
     test: /\.(s)?css$/, 
     loader: extractCSS.extract('css-loader!postcss-loader'), 
     }, 
     { 
     test: /\.json$/, 
     loader: 'json-loader', //reference by npm module or path to loader file 
     }, 
     { 
     test: /\.jpe?g$|\.gif$|\.png$|\.svg$|\.woff$|\.eot$|\.ttf$/, 
     loader: 'file-loader?name=assets/images/[sha512:hash:base64:7].[ext]', 
     exclude: root('node_modules'), 
     }, 
    ], 
    }, 

    plugins: [ 
    extractCSS, 
    new StaticHTMLPlugin(
     'bundle.js', 
     root('src/Routing.tsx'), 
     [ '.png', '.gif', '.jpg', '.jpeg', '.css', '.scss' ] 
    ), 
    ], 
} 

這裏是的package.json的副本:

"dependencies": {}, 
"devDependencies": { 
    "@types/history": "^2.0.39", 
    "@types/node": "^6.0.46", 
    "@types/react": "^0.14.44", 
    "@types/react-dom": "^0.14.18", 
    "@types/react-router": "^2.0.38", 
    "@types/winston": "0.0.29", 
    "css-loader": "^0.25.0", 
    "extract-text-webpack-plugin": "^1.0.1", 
    "file-loader": "^0.9.0", 
    "fs": "0.0.1-security", 
    "history": "^4.3.0", 
    "json-loader": "^0.5.4", 
    "postcss-assets": "^4.1.0", 
    "postcss-assets-rebase": "^0.4.0", 
    "postcss-cssnext": "^2.8.0", 
    "postcss-inline-svg": "^2.1.2", 
    "postcss-loader": "^0.13.0", 
    "precss": "^1.4.0", 
    "react": "^15.3.2", 
    "react-dom": "^15.3.2", 
    "react-router": "^3.0.0", 
    "stylelint": "^7.4.0", 
    "ts-loader": "^0.9", 
    "tsc": "^1.20150623.0", 
    "tslint": "^3.15", 
    "tslint-config-standard": "^1.3.0", 
    "tslint-eslint-rules": "^1.5.0", 
    "tslint-loader": "^2.1.5", 
    "tslint-react": "^1.0.0", 
    "typescript": "^2.0.3", 
    "typescript-react-router-static-html-webpack-plugin": "^0.1", 
    "webpack": "^1.13.2", 
    "webpack-dev-server": "^1.16.2", 
    "winston": "^2.2.0" 
} 

上有什麼可以怎麼回事任何想法?我對React庫本身並不是很熟悉。我沒有看到直接導出的屬性,但我還沒有深入挖掘lib,看看它們是否以另一種方式導出。

對於我來說,如果React lib和@ types/react typings之間的不一致,我會成爲唯一遇到這個問題的人,這似乎很奇怪。這就是爲什麼我傾向於這是某種配置問題。

我也在tsc上運行了這個項目,它似乎確實正確地構建了一些東西。雖然B/C TSC在控制檯中輸出數千條垃圾線,但很難確定。

謝謝。

回答

1

所以,這裏的解決方案是設置tsconfig.json道具,allowJsfalse

"compilerOptions": { 
    "allowJs": false 
} 

現在,我這裏的問題是,爲什麼?誰能解釋一下?