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 :
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
最满意答案
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创建一个将被永久调用的计划任务。 我目前正在阅读一些帖子,说有一个部分唤醒锁,我可以用来保持服务活着..这是正确的方法来做到这一点? 我不确定“它 ...
-
在后台运行服务(Run Service in the background)[2023-11-16]
这就是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 ...
-
服务在后台运行?(Service run in background?)[2022-02-06]
首先,你不需要通过一些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方法来设置重复时间。 看看这 ...