我已经搜遍了这个问题的解决方案,并且没有任何运气。我试图弄清楚为什么我会收到以下错误:
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本身并不十分熟悉。我没有看到直接导出的属性,但我还没有深入挖掘lib,看看它们是否以其他方式导出。
如果React lib与@ types / react类型之间存在不一致,我会感到很奇怪,我是唯一遇到此问题的人。这就是为什么我倾向于这是一种配置问题。
我也在tsc
上运行该项目,似乎实际上正确地构建了一些东西。虽然b / c tsc在控制台中输出了数千条垃圾线,但很难确定。
感谢。
答案 0 :(得分:1)
所以,这里的解决方案是将tsconfig.json
道具,allowJs
设置为false
:
"compilerOptions": {
"allowJs": false
}
现在,我在这里的问题是为什么?谁能解释一下?