I have very simple TypeScript app, which piles fine using webpack, but gives me an error "Build:Cannot find module 'react'" when trying to build in Visual Studio. I'm stuck, any help is appreciated.
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"
}
}
I have very simple TypeScript app, which piles fine using webpack, but gives me an error "Build:Cannot find module 'react'" when trying to build in Visual Studio. I'm stuck, any help is appreciated.
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:
{
"pilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"jsx": "preserve",
"module": "monjs"
}
}
Hello.tsx:
import * as React from "react";
interface IHelloProps { piler: number }
export class Hello extends React.Component<IHelloProps, {}> {
render() {
return <div > Hell no 2!</div >
}
}
Share
Improve this question
asked Nov 18, 2016 at 5:22
Maxim AlexeyevMaxim Alexeyev
1,0311 gold badge11 silver badges26 bronze badges
4
- Everything looks fine which makes me wonder. Have you run npm install ? – Edwin Kato Commented Nov 18, 2016 at 8:12
- if I run "npm link typescript" and then "typings install --global --save dt~react" it helps, but after that I seems to always have conflict with my @type folder in node_modules when piling from webback, and after that have problem with other package, react-router to be exact. – Maxim Alexeyev Commented Nov 18, 2016 at 13:19
-
Try this. Delete your node modules folder then Go to the root folder of your app and run
npm install
....Then give me feedback after that – Edwin Kato Commented Nov 18, 2016 at 13:25 - Sorry, couldn't get to this lately. I started brand new application, just to have very clean start. Got to the same point. I now realized that I don't want to use typings with new version of typescript, but I'm where I was, piles from web pack, and cannot find module in Visual Studio – Maxim Alexeyev Commented Nov 20, 2016 at 22:00
1 Answer
Reset to default 4I got it all resolved by installing latest version (2.0.6.0) from here: https://www.microsoft./en-us/download/details.aspx?id=48593