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> ); }, 
  • import CheckboxInput from './Checkbox.jsx' - Alex Slobodyansky
  • @AlexSlobodyansky Unfortunately not working. - Aynur Sibagatullin
  • @AlexSlobodyansky If you import it like this: var CheckboxInput = require (__ dirname + '\\ Components \\ CheckboxInput.jsx'), then another error occurs: Uncaught SyntaxError: Unexpected token import - Aynur Sibagatullin
  • There instead of Checkbox.jsx should be CheckboxInput.jsx. I wrote wrong. Do you also have the name of the file from which the class is imported? - Alex Slobodyansky
  • one
    @AynurSibagatullin You use too many new technologies for yourself at once (and you don’t understand any of them) and hope that someone will figure out your zoo for you. If one layer of abstraction flows, then you can remotely debug it, if several - it is rather difficult, because you can make mistakes in two dozen places and try to understand exactly which (or rather several at once) for quite a long time. Make work at least some piece and not all in a bundle. - Duck Learns to Take Cover

0