首页 \ 问答 \ Browserify Rails错误 - ParseError:'import'和'export'可能只与'sourceType:module'一起出现(Browserify Rails Error - ParseError: 'import' and 'export' may appear only with 'sourceType: module')

Browserify Rails错误 - ParseError:'import'和'export'可能只与'sourceType:module'一起出现(Browserify Rails Error - ParseError: 'import' and 'export' may appear only with 'sourceType: module')

最近我想在我的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>

我已经搞乱了我的gemfile,如下所示。 也许这就是问题发生的原因:

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'

有人可以帮我解决这个错误?


Recently i want to integrated NPM package in my rails application. I getting this problem :

enter image description here

I search in this forum if someone have same problem like me. Yes, i saw similar question being posted here but they're having different error.

Below is what i have in my 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(); });

Here's where i try to imported the package

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>

I have mess up my gemfile for like below. Maybe this is why the problem occur :

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'

someone can help me to solve this error ?


原文:https://stackoverflow.com/questions/43625591
更新时间:2023-05-16 20:05

最满意答案

Android TimerTask示例
TimerTask表示任务将运行指定的时间,它将只运行一次或重复。
创建新的类新的TimerTask。
TimerTask有两种方法。

--> 
1 .scheduledExecutionTime() // Repeat Task
2 .schedule() //Only once
Timer singleTask = new Timer();
Timer repeatTask = new Timer();

int singleTaskInterval = 3000; // 3 sec
int repeatInterval = 10000; // 10 sec

 // this task for specified time only once it will run
singleTask.schedule(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run 3 sec only once.
}
}, 1000);

  // this task for specified time it will run Repeat
repeatTask.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run every 10 sec repeat
}
}, 0, repeatInterval);

When your activity went to destroy or stop . you should cancel this task
--> --> 
@Override
protected void onDestroy(){
super.onDestroy();
if(singleTask != null){
singleTask.cancel();
}
if(repeatTask != null){
repeatTask.cancel();
}
}
Activity Code
/**
*
* @author vijayakumar
*
*/
public class AndroidMADQAActivity extends Activity {
/** Called when the activity is first created. */
Timer singleTask = new Timer();
Timer repeatTask = new Timer();
int singleTaskInterval = 3000; // 3 sec
int repeatInterval = 10000; // 10 sec
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
singleTask.schedule(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run 3 sec only once.
}
}, 1000);
repeatTask.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run every 10 sec repeat
}
}, 0, repeatInterval);
}
@Override
protected void onDestroy(){
super.onDestroy();
if(singleTask != null){
singleTask.cancel();
}
if(repeatTask != null){
repeatTask.cancel();
}
}
}

Android TimerTask Example
TimerTask Represents the task will run specified time and it will run only once or Repeat.
Create new Class new TimerTask.
TimerTask Having two methods.

--> 
1 .scheduledExecutionTime() // Repeat Task
2 .schedule() //Only once
Timer singleTask = new Timer();
Timer repeatTask = new Timer();

int singleTaskInterval = 3000; // 3 sec
int repeatInterval = 10000; // 10 sec

 // this task for specified time only once it will run
singleTask.schedule(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run 3 sec only once.
}
}, 1000);

  // this task for specified time it will run Repeat
repeatTask.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run every 10 sec repeat
}
}, 0, repeatInterval);

When your activity went to destroy or stop . you should cancel this task
--> --> 
@Override
protected void onDestroy(){
super.onDestroy();
if(singleTask != null){
singleTask.cancel();
}
if(repeatTask != null){
repeatTask.cancel();
}
}
Activity Code
/**
*
* @author vijayakumar
*
*/
public class AndroidMADQAActivity extends Activity {
/** Called when the activity is first created. */
Timer singleTask = new Timer();
Timer repeatTask = new Timer();
int singleTaskInterval = 3000; // 3 sec
int repeatInterval = 10000; // 10 sec
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
singleTask.schedule(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run 3 sec only once.
}
}, 1000);
repeatTask.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Here do something
// This task will run every 10 sec repeat
}
}, 0, repeatInterval);
}
@Override
protected void onDestroy(){
super.onDestroy();
if(singleTask != null){
singleTask.cancel();
}
if(repeatTask != null){
repeatTask.cancel();
}
}
}

相关问答

更多
  • 在我第一次尝试时,我在服务班使用计时器,并且每10分钟安排一次电池检查。 但很快我发现当屏幕熄灭时服务暂停。 你可能没有WakeLock一个WakeLock ,所以该设备睡着了。 看起来AlarmService在几个小时后停止 我相当怀疑它。 所以我的问题是,有没有人写过一些服务在后台运行(像永远)? 无法创建永久运行的服务。 应该可以通过AlarmManager创建一个将被永久调用的计划任务。 我目前正在阅读一些帖子,说有一个部分唤醒锁,我可以用来保持服务活着..这是正确的方法来做到这一点? 我不确定“它 ...
  • 这就是IntentService工作原理。 IntentService是服务的基类,可根据需要处理异步请求(表示为Intents)。 [...] [...] IntentService将接收Intents,启动工作线程,并根据需要停止服务。 所有请求都在一个工作线程上处理 - 它们可能需要多长时间(并且不会阻止应用程序的主循环),但一次只能处理一个请求。 只要有要处理的任务,服务就会生效。 之后,服务将结束并重新启动下一个任务。 如果你想拥有一个正在运行的服务 ,甚至可能是一个绑定服务 ,你必须直接子类化S ...
  • 请参阅iPhoneAppProgrammingGuide的 “后台执行”部分。 简而言之,您的应用程序必须是以下类型之一: 在后台向用户播放声音内容的应用程序,如音乐播放器应用程序 允许用户随时了解其位置的应用程序,例如导航应用程序 支持互联网语音协议(VoIP)的应用程序 需要下载和处理新内容的报亭应用 从外部配件接收定期更新的应用程序 您必须添加到Info.plist,如下所示:将UIBackgroundModes键添加到Info.plist文件中,并将其值设置为包含以下一个或多个字符串的数组: 音频 ...
  • 正如Apple在其文档中所述 : 在iOS中,只允许在后台运行特定的应用类型: 在后台播放用户可听内容的应用,例如音乐播放器应用 在后台录制音频内容的应用程序 可让用户随时了解其位置的应用,例如导航应用 支持互联网协议语音(VoIP)的应用 需要定期下载和处理新内容的应用 从外部配件接收定期更新的应用程序 实现这些服务的应用程序必须声明它们支持的服务,并使用系统框架来实现这些服务的相关方面。 声明服务可以让系统知道您使用哪些服务,但在某些情况下,系统框架实际上会阻止您的应用程序被挂起。 您可以阅读有关在链接 ...
  • 使用AlarmManager执行重复任务。 // Setup a recurring alarm every half hour public void scheduleAlarm() { // Construct an intent that will execute the AlarmReceiver Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class); // Create ...
  • 来自iOS开发人员库: iOS 7支持两种新的应用背景执行模式: 经常需要新内容的应用程序可以向系统注册并被唤醒或定期启动以在后台下载该内容。 要注册,请在应用程序的Info.plist文件中包含带有提取值的UIBackgroundModes键,并使用setMinimumBackgroundFetchInterval:方法设置获取操作之间的最短时间。 您还必须在application:performFetchWithCompletionHandler:程序委托中实现application:performFe ...
  • Android TimerTask示例 TimerTask表示任务将运行指定的时间,它将只运行一次或重复。 创建新的类新的TimerTask。 TimerTask有两种方法。 --> 1 .scheduledExecutionTime() // Repeat Task 2 .schedule() //Only once Timer singleTask = new Timer(); Timer repeatTask = new Timer(); int singleTaskInterval = 3000 ...
  • 首先,你不需要通过一些ActivityManager方法来检查你的Service是否正在运行。 如果您在onResume()调用startService() && bindService() ,则Android足够聪明,只要它已经运行就可以绑定到Service ,如果没有,它将创建Service并通过其正确的记录生命周期,然后绑定到它。 你可以在这里做的是这样的: @Override public void onResume() { super.onResume(); Intent inte ...
  • 如果您只想在应用程序运行时调用服务器,则无需使用警报管理器。 还有其他选择 CoundDownTimer 线 在这种情况下我更喜欢CoundownTimer,你可以这样使用 CountDownTimer countDownTimer = new CountDownTimer(1000000, 60 * 1000) { @Override public void onTick(long millisUntilFinished) { // Do something on ...
  • 您必须使用AlarmManager来启动您的服务。 要使用AlarmManager,您需要一个您想要警报触发的待处理Intent。 像这样: 首先,创建一个将由一个Intent触发的Receiver, 在您的活动中,创建触发Receiver的意图, 为触发接收器的意图创建一个挂起的意图,最后4.使用警报管理器触发挂起的意图。 请记住,当收到来自您的报警管理器的内容时,您的Receiver将通过Intent启动您的服务。 您可以使用alarmManager的setRepeating方法来设置重复时间。 看看这 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)