首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Browserify-shim Poltergeist/Phantom.JS严格模式问题

Browserify-shim Poltergeist/Phantom.JS严格模式问题
EN

Stack Overflow用户
提问于 2016-05-12 05:30:05
回答 1查看 466关注 0票数 0

我正在使用Browserify制作一个Rails project。Bootstrap Javascript通过browserify-shim加载。

当我启动我的项目并在Firefox中查看它时,一切都是正确的。但是,当我通过Poltergeist测试它(或者只是从PhantomJS 2.1.1启动它)时,出现了一个错误:

代码语言:javascript
复制
 Capybara::Poltergeist::JavascriptError:
   One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).                                                                                                                                                          

   ReferenceError: Strict mode forbids implicit creation of global property 'jQuery'
   ReferenceError: Strict mode forbids implicit creation of global property 'jQuery'
       at http://127.0.0.1:47269/assets/application-038b5f3da112b67153daa218adfed54030ee9e0085fd9586c0bb13fa320b830e.js:12

下面是问题所在的代码:

代码语言:javascript
复制
;jQuery = global.jQuery = require("jquery");

对我来说,它看起来像是jQuery的填充行(后面有bootstrap.js代码)。

这是我的package.json:

代码语言:javascript
复制
{
  "name": "billy-bones-rails",
  "version": "0.0.1",
  "description": "Billy-bones-rails asset package",
  "main": "index.js",
  "directories": {
    "doc": "doc",
    "test": "test"
  },
  "scripts": {
    "bundle-js": "./node_modules/.bin/browserify app/assets/javascripts/index.js -o app/assets/javascripts/bundle.js",
    "watch-js": "./node_modules/.bin/watchify    app/assets/javascripts/index.js -o app/assets/javascripts/bundle.js -d -v"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/art-solopov/billy-bones-rails.git"
  },
  "author": "Artemiy Solopov",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/art-solopov/billy-bones-rails/issues"
  },
  "homepage": "https://github.com/art-solopov/billy-bones-rails#readme",
  "dependencies": {
    "babel-cli": "^6.8.0",
    "babel-preset-es2015": "^6.6.0",
    "babelify": "^7.3.0",
    "bootstrap": "^3.3.6",
    "browserify": "^13.0.0",
    "browserify-shim": "^3.8.12",
    "jquery": "^2.2.2",
    "normalize.css": "^4.0.0",
    "watchify": "^3.7.0"
  },
  "browser": {
    "bootstrap": "./node_modules/bootstrap/dist/js/bootstrap.js"
  },
  "browserify": {
    "transform": [
      "browserify-shim",
      [
        "babelify",
        {
          "presets": "es2015"
        }
      ]
    ]
  },
  "browserify-shim": {
    "bootstrap": {
      "depends": [
        "jquery:jQuery"
      ]
    }
  }
}

除了禁用Poltergeist错误报告之外,我还能对此错误做些什么吗?

另外,应该注意的是,我只能使用PhantomJS 2.1.1复制这个错误。火狐(46和48),铬和PhantomJS 1.9.0输出没有错误。

EN

回答 1

Stack Overflow用户

发布于 2016-05-14 04:34:52

显然,这个问题是由babelify错误配置和browserify-shim造成的。我将以下内容添加到我的babelify配置中:

代码语言:javascript
复制
"ignore": "node_modules"

这摆脱了Bootstrap模块中的顶级严格模式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37173611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档