ruby on rails - Can't install a npm module with webpacker-react -
i install react-dropzone in project. use react-rails project. had installed webpacker-react use gem. installed react-dropzone via npm install
, can't load in react components. (i suppose it's due webpacker-react). so, how load modules installed via npm react components?
component.jsx
import dropzone 'react-dropzone' class main extends react.component { ondrop(file) { } render() { return ( <div classname="container"> <div> <dropzone ondrop={this.ondrop().bind(this)}> <p>to fix</p> </dropzone> </div> </div> ) } }
package.json (well installed)
"react-dropzone": "^3.13.3",
error message in firefox console:
referenceerror: require not defined in debugger : var _reactdropzone = require('react-dropzone');
webpacker.yml
default: &default source_path: app/javascript source_entry_path: packs public_output_path: packs extensions: - .coffee - .erb - .js - .jsx - .ts - .vue - .sass - .scss - .css - .png - .svg - .gif - .jpeg - .jpg development: <<: *default dev_server: host: 0.0.0.0 port: 8080 https: false test: <<: *default public_output_path: packs-test production: <<: *default
configuration.js
//common configuration webpacker loaded config/webpacker.yml const { join, resolve } = require('path') const { env } = require('process') const { safeload } = require('js-yaml') const { readfilesync } = require('fs') const configpath = resolve('config', 'webpacker.yml') const loadersdir = join(__dirname, 'loaders') const settings = safeload(readfilesync(configpath), 'utf8')[env.node_env] function removeouterslashes(string) { return string.replace(/^\/*/, '').replace(/\/*$/, '') } function formatpublicpath(host = '', path = '') { let formattedhost = removeouterslashes(host) if (formattedhost && !/^http/i.test(formattedhost)) { formattedhost = `//${formattedhost}` } const formattedpath = removeouterslashes(path) return `${formattedhost}/${formattedpath}/` } const output = { path: resolve('public', settings.public_output_path), publicpath: formatpublicpath(env.asset_host, settings.public_output_path) } module.exports = { settings, env, loadersdir, output }
Comments
Post a Comment