I have one CheckboxInput class and one Login component. They are stored in the same folder in different files. And the problem is that I cannot use CheckboxInput in the Login component.
CheckboxInput.jsx :
CheckboxInput = React.createClass({ //Тут рабочий код. Если я объявляю это в Login, то всё работает. }); export default CheckboxInput; None of the calls listed below work.
Login :
var CheckboxInput = require('CheckboxInput'); import {CheckboxInput} from 'CheckboxInput'; import CheckboxInput from 'CheckboxInput'; Here is what it gives at startup:
Uncaught Error: Cannot find module './CheckboxInput.jsx' module.js:340 i @ babel.min.js:23 What's wrong? What should be done?
Update
webpack.config.js :
var webpack = require('webpack'); var webpackTargetElectronRenderer = require('webpack-target-electron-renderer'); var config = { //entry: [ 'webpack-hot-middleware/client?reload=true&path=http://localhost:9000/__webpack_hmr', './src/index', ], entry: [ './main.js'], module: { loaders: [{ test: /\.jsx?$/, loaders: ['babel-loader'], exclude: /node_modules/ }, { test: /\.css$/, loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader' }, { test: /\.png|\.svg$/, loaders: ['file-loader'] }, query: { presets: ['es2015', 'react'] }] }, resolve: { extensions: ['', '.js', '.jsx'], }, plugins: [ new webpack.HotModuleReplacementPlugin(), new NpmInstallPlugin({ dev: function(module, path) { return [ "babel-preset-react-hmre", "webpack-dev-middleware", "webpack-hot-middleware", ].indexOf(module) !== -1; }, }) ] }; config.target = webpackTargetElectronRenderer(config); module.exports = config; Update number 2
If I try like this:
var CheckboxInput = require(__dirname+'\\Components\\CheckboxInput.jsx'); It displays the following error:
Uncaught SyntaxError: Unexpected token import file: Fix import on this:
"use strict"; const React = require('react'); const ReactDOM = require('react-dom'); In the future, it displays:
Uncaught SyntaxError: Unexpected token < that is, it no longer understands the render () function:
render: function () { return ( <label> <input type="checkbox" style={{cursor:'pointer'}} name={this.props.name} checked={this.state.checked} onChange={this.handleClick} value={this.props.value} /> {this.props.label} </label> ); },