Javascript 对象不支持此属性或方法 Rails Windows 64bit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28312460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:36:20  来源:igfitidea点击:

Object doesn't support this property or method Rails Windows 64bit

javascriptruby-on-rails

提问by Matt P

I installed Rails on my Surface Pro 3 and run into this error after trying to view a page. I have tried several suggestions such as installing rubyracer with libv8 but it didn't help.

我在 Surface Pro 3 上安装了 Rails,并在尝试查看页面后遇到此错误。我尝试了一些建议,例如使用 libv8 安装 ruby​​racer,但没有帮助。

TypeError: Object doesn't support this property or method (in c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)

类型错误:对象不支持此属性或方法(在 c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.咖啡)

Here is my gemfile:

这是我的 gemfile:

source 'http://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer',  platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'libv8', '~> 3.16.14.7'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'font-awesome-rails'
gem 'simple_form'
gem 'devise'

采纳答案by Ralph Ritoch

Contrary to popular belief, Rails is NOT cross platform compatible as they claim. If it was it would work on windows, out of the box. Like you I have tried every available option.

与流行的看法相反,Rails 并不像他们声称的那样跨平台兼容。如果是这样,它可以在 Windows 上运行,开箱即用。像你一样,我已经尝试了所有可用的选项。

This was solved using Ruby 2.1.5p273/Rails 4.2.0

这是使用 Ruby 2.1.5p273/Rails 4.2.0 解决的

I changed execjs to use UTF-8 with jscript, no effect. This was done by editing C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\execjs-2.2.2\lib\execjs\runtimes.rbchanging the JScript = block to the following.

我将 execjs 更改为在 jscript 中使用 UTF-8,没有效果。这是通过编辑C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\execjs-2.2.2\lib\execjs\runtimes.rb将 JScript = 块更改为以下内容来完成的。

JScript = ExternalRuntime.new(
  name:        "JScript",
  command:     "cscript //E:jscript //Nologo",
  runner_path: ExecJS.root + "/support/jscript_runner.js",
  encoding:    'UTF-8' # CScript with //U returns UTF-16LE
)

I also tried installing therubyracer which leads to problems with the libv8 dependency not compiling. I added my python 2.7 install to the windows system path, and installed libv8. Then it said libv8 was installed but when I tried to install therubyracer it said libv8 couldn't be found. I uninstalled libv8 and tried again and it said libv8 couldn't be compiled. That was enough for me to determine that therubyracer was not going to work on windows, so I commented it out of my Gemfile, leaving python 2.7 on my windows system path.

我还尝试安装 therubyracer,这导致 libv8 依赖项无法编译。我将我的 python 2.7 安装添加到 Windows 系统路径,并安装了 libv8。然后它说安装了 libv8,但是当我尝试安装 therubyracer 时,它说找不到 libv8。我卸载了 libv8 并再次尝试,它说无法编译 libv8。这足以让我确定 therubyracer 不能在 Windows 上运行,所以我将它从 Gemfile 中注释掉,将 python 2.7 留在我的 Windows 系统路径上。

I updated coffee-script-source, by adding the following to my Gemfile

我更新了 coffee-script-source,将以下内容添加到我的 Gemfile 中

gem 'coffee-script-source', '1.9.0'

After adding coffee-script-source to my Gemfile I ran gem update coffee-script-source, this also didn't solve the problem.

将 coffee-script-source 添加到我的 Gemfile 后,我运行了gem update coffee-script-source,这也没有解决问题。

I then installed node.js, this worked for 5 minutes until I generated a new controller, and it was broken again.

然后我安装了 node.js,这工作了 5 分钟,直到我生成了一个新的控制器,它又坏了。

Note: After installing node.js you need to open a new command prompt to get the updates to your system path that are setup when node.js installs.

注意:安装 node.js 后,您需要打开一个新的命令提示符以获取安装 node.js 时设置的系统路径的更新。

Finally what fixed this problem was to open up the app\assets\javascripts\application.jsfile and remove the last line which says

最后解决这个问题的是打开app\assets\javascripts\application.js文件并删除最后一行

//= require_tree .

//= require_tree .

Lastly run the following command to make sure coffee-script is properly installed in Node.js

最后运行以下命令以确保在 Node.js 中正确安装了 coffee-script

npm install -g coffee-script

回答by Jessa

Coffee script 1.9.0 doesn't play well with Windows. On my Windows 7 machine, using version 1.8.0 solved this problem.

Coffee 脚本 1.9.0 不能很好地与 Windows 配合使用。在我的 Windows 7 机器上,使用 1.8.0 版解决了这个问题。

Add to Gemfile

添加到 Gemfile

gem 'coffee-script-source', '1.8.0'

then, run

然后,运行

bundle update coffee-script-source

and restart the server (if needed)

并重新启动服务器(如果需要)

回答by Jaime

Had the same issue (doing a 'hello world' application of all things...) but couldn't get the coffeescript 1.8.0 fix to work. Found a solution here: http://mech.xyz/how-to-fix-ruby-on-rails-turbolinks-js-coffee-error-windows/

有同样的问题(对所有事情做一个“hello world”应用程序......)但无法使 coffeescript 1.8.0 修复工作。在这里找到了解决方案:http: //mech.xyz/how-to-fix-ruby-on-rails-turbolinks-js-coffee-error-windows/

Steps:

脚步:

  1. Navigate to \app\views\layouts\application.html.erb
  2. Change line 6 from
  1. 导航到 \app\views\layouts\application.html.erb
  2. 将第 6 行从

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

to

<%= javascript_include_tag '**defaults**', 'data-turbolinks-track' => true %>

<%= javascript_include_tag '**defaults**', 'data-turbolinks-track' => true %>

Did this and it's been working fine now.

这样做了,现在工作正常。

回答by superluminary

This is caused by an incompatibility between 64bit Windows and the CoffeeScript gem.

这是由 64 位 Windows 和 CoffeeScript gem 之间的不兼容造成的。

This is indeed a CoffeeScript issue. It only appears to affect 64 bit Windows machines. 32bit Windows is fine.

这确实是一个 CoffeeScript 问题。它似乎只影响 64 位 Windows 机器。32 位 Windows 没问题。

CoffeeScript occurs in two places by default in Rails:

在 Rails 中,CoffeeScript 默认出现在两个地方:

  • The default scaffold generator makes a coffee script file.
  • Turbolinks is CoffeeScript.
  • 默认脚手架生成器制作咖啡脚本文件。
  • Turbolinks 是 CoffeeScript。

The simplest way to fix this is to simply remove the CoffeeScript. You probably don't need it anyway.

解决此问题的最简单方法是简单地删除 CoffeeScript。反正你可能不需要它。

  1. Delete the generated coffeeScript file in app/assets/javascripts.
  2. Remove the turbolinks gem from the gemfile, then bundle install.
  3. Edit assets/stylesheets/application.js to delete the turbolinks include.
  1. 删除 app/assets/javascripts 中生成的 coffeeScript 文件。
  2. 从 gemfile 中删除 turbolinks gem,然后捆绑安装。
  3. 编辑 assets/stylesheets/application.js 以删除 turbolinks include。

回答by suhao399

I found your error look like this ExecJS::RuntimeError on Windows trying to follow rubytutorial

我发现你的错误看起来像 Windows 上的 ExecJS::RuntimeError 试图遵循 ruby​​tutorial

I fix on my system by un-comment the line // = require_tree in 'assets\javascripts\application.js'

我通过取消注释“assets\javascripts\application.js”中的行 // = require_tree 来修复我的系统

= require_tree