最近我想在我的rails应用程序中集成NPM包。我遇到了这个问题:
我在这个论坛中搜索是否有人和我一样有问题。是的,我在这里看到了类似的问题,但他们有不同的错误。
以下是我在application.js中的内容:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require react
//= require react_ujs
//= require components
//= require react-select
//= require react-dom
//= require classnames
//= require_tree .
$(function(){ $(document).foundation(); });

我试图导入包
var React = require('react');
var ReactDOM = require('react-dom');
var FileBase64 = require('react-file-base64');
var MembersNew = React.createClass(
{
render()
{
return(
<div>
<h5>ACCOUNT DETAILS</h5>
<hr/>
<p>Fill in your member account details below</p>
<b>Membership ID : </b>
<div className="row">
<div className="medium-6 columns">
<label>Username*
<input ref="name" type="text"/>
</label>
<label>First Name*
<input ref="name" type="text"/>
</label>
<label>Last Name*
<input ref="name" type="text"/>
</label>
<label>Email Address*
<input ref="name" type="text"/>
</label>
</div>
&#13;
我把我的宝石文件搞砸了,如下所示。也许这就是问题发生的原因:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rails-assets-react-select','~> 1.0.0.rc.3', source: 'https://rails-assets.org'
gem 'rails-assets-react-dom', source: 'https://rails-assets.org'
gem 'rails-assets-classnames', source: 'https://rails-assets.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'react-rails'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'responders'
gem 'foundation-rails'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'browserify-rails'
&#13;
有人可以帮我解决这个错误吗?
答案 0 :(得分:0)
我认为您可能遇到的问题是您尝试安装和使用的npm模块是ES6 JS模块。从您的错误日志中,我猜您正在使用Browserify来加载您的JS模块。 IIRC Browserify开箱即用只支持Common JS模块,这意味着您必须通过Babel或Babelify(babel的browserify转换)等工具运行您的JS,以便使用module.exports
语法将ES6模块转换为ES5模块