在Visual Studio下编译时找不到模块
Cannot find module when compiling under Visual Studio
我有一个非常简单的TypeScript应用程序,它使用webpack编译得很好,但是当试图在Visual Studio中构建时,给了我一个错误"Build:Cannot find module 'react'"。我被卡住了,任何帮助都很感激。
package.json:
{
"name": "react-router-test",
"version": "1.0.0",
"description": "",
"main": "./dist/bundle.js",
"scripts": {
"test": "echo '"Error: no test specified'" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.4.0",
"react-dom": "^15.4.0",
"react-router": "^3.0.0"
},
"devDependencies": {
"@types/react": "^0.14.49",
"@types/react-dom": "^0.14.18",
"@types/react-router": "^2.0.39",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"ts-loader": "^1.2.1",
"typescript": "^2.0.10",
"webpack": "^1.13.3"
}
}
webpack.config.js:
module.exports = {
entry: "./src/Index.tsx",
output: {
filename: "./dist/bundle.js"
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
//loaders: [
// { test: /'.tsx$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react!ts-loader' }
loaders: [
{
test: /'.ts(x?)$/,
loader: "babel-loader!ts-loader"
},
]
},
devServer: {
contentBase: ".",
host: "localhost",
port: 8081
},
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
}
tsconfig.json:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"jsx": "preserve",
"module": "commonjs"
}
}
Hello.tsx:
import * as React from "react";
interface IHelloProps { compiler: number }
export class Hello extends React.Component<IHelloProps, {}> {
render() {
return <div > Hell no 2!</div >
}
}
我通过安装最新版本(2.0.6.0)从这里解决了所有问题:https://www.microsoft.com/en-us/download/details.aspx?id=48593
相关文章:
- 找不到模块捆绑包
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- 因果报应-找不到模块:错误:无法解析模块'scs'
- module.js在运行iron节点时找不到模块
- 错误:找不到模块'/lib/cli'
- nodeJS中的uglify js“;找不到模块“”;
- 找不到模块'它'当用摩卡/柴测试时
- 余烬引擎未捕获错误:找不到模块余烬视图/views/select
- 使用状态语法后找不到模块
- 节点.js:找不到模块“柴”
- 错误:使用摩卡测试时找不到模块
- nodemon找不到模块'/路径/to/project/home/index.js'
- 接收'错误:找不到模块'使用browserfy、gullow、react.js
- Sails.js+Grunt"找不到模块“”;错误
- 找不到模块“;睡眠”;,跳跃动作
- 找不到模块 './build/Release/bson'] 代码: 'MODULE_NOT_FOUND' } js-bs
- 错误:找不到模块'开放星云'(Meteor.JS)
- 错误:找不到模块,但仅在Heroku上
- 错误:找不到模块'html',可以't提供静态文件
- Gulp测试找不到模块