更新
毕竟它可能是TypeScript issue,可能是a PR merged earlier today。
我最初将此帖子发布到https://github.com/Microsoft/TypeScript/issues,但被告知这可能不是TypeScript错误。
我正在使用带有webpack和ts-loader的typescript @ next。
运行Webpack时,我从typescript.js收到以下错误:43445
C:\Users\Michael\Development\Replicate>webpack
Using config file at C:\Users\Michael\Development\Replicate\tsconfig.json
C:\Users\Michael\Development\Replicate\node_modules\typescript\lib\typescript.js:43445
throw new Error("Could not find file: '" + fileName + "'.");
^
Error: Could not find file: 'C:/Users/Michael/Development/Replicate/node_modules/react/package.json'.
at getValidSourceFile (C:\Users\Michael\Development\Replicate\node_modules\typescript\lib\typescript.js:43445:23)
at Object.getSyntacticDiagnostics (C:\Users\Michael\Development\Replicate\node_modules\typescript\lib\typescript.js:43615:52)
at C:\Users\Michael\Development\Replicate\node_modules\ts-loader\index.js:186:42
at Array.forEach (native)
at Compiler.<anonymous> (C:\Users\Michael\Development\Replicate\node_modules\ts-loader\index.js:185:14)
at Compiler.applyPlugins (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\node_modules\tapable\lib\Tapable.js:26:37)
at Compiler.<anonymous> (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:193:12)
at Compiler.emitRecords (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:282:37)
at Compiler.<anonymous> (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:187:11)
at C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:275:11
at Compiler.applyPluginsAsync (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\node_modules\tapable\lib\Tapable.js:60:69)
at Compiler.afterEmit (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:272:8)
at Compiler.<anonymous> (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:267:14)
at C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\node_modules\async\lib\async.js:52:16
at done (C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\node_modules\async\lib\async.js:248:21)
at C:\Users\Michael\AppData\Roaming\npm\node_modules\webpack\node_modules\async\lib\async.js:44:16
at FSReqWrap.oncomplete (fs.js:95:15)
我的package.json
{
"name": "Replicate",
"version": "1.0.0",
"description": "Reproducing typescript file not found bug",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Michael Ross",
"license": "MIT",
"dependencies": {
"react": "^0.13.3",
"ts-loader": "^0.5.0",
"typescript": "^1.6.0-dev.20150825"
}
}
我的webpack.config.js
module.exports = {
entry: "./app.tsx",
output: {
filename: "bundle.js"
},
resolve: {
extensions: ["", ".tsx", ".ts", ".js"]
},
module: {
loaders: [
{ test: /\.ts(x?)$/, loader: "ts-loader" }
]
}
}
我的app.tsx
import React = require('react');
class Demo extends React.Component<any, any> {
render() {
return <div>Trying to replicate</div>
}
}
React.render(<Demo />, document.getElementById("demo"));
以防万一,我的tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "react",
"sourceMap": true
},
"files": [
"./typings/tsd.d.ts",
"./app.tsx"
]
}
和tsd.json
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"react/react.d.ts": {
"commit": "71a7d5306ae4f9893aafd2d85d38aac8789ebf33"
}
}
}
如果我遇到配置错误,我们非常感谢您提供帮助和指导。谢谢!
答案 0 :(得分:0)
变化:
import React = require('react');
要:
var React = require('react');
除非你的es6方式应该是:
import React from "react";
这可能是问题。