【发布时间】:2016-05-11 21:30:04
【问题描述】:
我正在使用 Browserify 制作 Rails project。 Bootstrap Javascript 是通过 browserify-shim 加载的。
当我启动我的项目并在 Firefox 中查看它时,一切正常。但是,当我通过 Poltergeist 测试它时(或者只是使用 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 的填充线(后面有 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"
]
}
}
}
除了禁用 Poltergeist 错误报告之外,我可以对这个错误做任何事情吗?
P。 S. 应该注意的是,我只能使用 PhantomJS 2.1.1 复制此错误。 Firefox(46 和 48)、Chromium 和 PhantomJS 1.9.0 输出没有错误。
【问题讨论】:
标签: javascript jquery phantomjs browserify browserify-shim