私はBrowserifyを使用してprojectを作成しています。 Bootstrap Javascriptはbrowserify-shimから読み込まれます。Browserify-shim Poltergeist/Phantom.JS厳密モードの問題
私のプロジェクトを起動してFirefoxで見ると、すべて正しいです。私はポルターガイストを経由して、それをテストする(あるいは単にPhantomJS 2.1.1とそれを起動)していたときただし、エラーが発生します。
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
は、ここで問題になっているラインです:
;jQuery = global.jQuery = require("jquery");
私には、 jQueryのshim行のように見えます(それに続くbootstrap.jsコードがあります)。ここで
は私のpackage.jsonです:
{
"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"
]
}
}
}
私はポルターガイストのエラー報告を無効にした場合の外に、このエラーで何かをすることはできますか?
P.S.私はPhantomJS 2.1.1を使用してこのエラーを再現できるだけであることに注意してください。 Firefox(46と48)、ChromiumとPhantomJS 1.9.0はエラーを出力しません。