I am using selenium-webdriver module on npm and my code is =
const selenium = require('selenium-webdriver');
const { Builder, By, Key } = selenium;
(async() => {
const driver = await new Builder().forBrowser('chrome').withCapabilities(selenium.Capabilities.chrome().set('chrome.binary', './drivers/chromedriver.exe')).build();
})();
It gives me the error Error: The ChromeDriver could not be found on the current PATH. I downloaded chromedriver then try both using .withCapabilities(that part is still inside the code above) and export PATH=$PATH: but both not worked still giving same error I have chromedriver in a folder called drivers and that folder is on same folder with my index.js file I think my path writing is wrong but I really don't know how to do it can someone help?
As #Max Daroshchanka suggested in the comments section, first thing is that you must have the path to the executable chrome.exe for the "chrome.binary" option.
Secondly, I will suggest that you have the same version for chromedriver.exe and your chrome.exe. I faced the same issue because I was not having the same version.
Now the following is something that did not work for me. Could not be the case with you.
Thirdly, I will also suggest that instead of relying on the node.js (or any package manager's) library (this gets created when you perform npm install, for every dependency there is a /lib folder created that has the executable) to add the required chromedriver.exe file. What I mean is manually download the required version driver file from here:
http://chromedriver.storage.googleapis.com/index.html
and add this downloaded extracted path to the PATH env variable.
Related
Is there a way to check the version of a module from within a script?
Based on my Python experience, I tried this:
const someModule = require('some-module');
someModule.version
But no dice. Is there any other way to do this? I'm suspecting I'm not getting the version I thought I was and I'd like to check.
When searching all I get is people repeatedly instructing how to get a module's version on the command line.
You can use require.resolve, to get the directory of your module.
Then simply join the path from this with package.json, from this you can get the version.
eg..
const { dirname, join } = require("path");
const ver = require(join(
dirname(require.resolve("react")),
"package.json"
)).version;
console.log(ver);
I have created a npm package named test_package_cat, which is supposed to read a json file (info.json) at the beginning.
Thus, index.js (main entry) and info.json are at the same level.
When I run the index.js locally, I can read the file.
either:
fs.readFileSync('info.json')
or
fs.readFileSync(path.resolve(__dirname, 'info.json')
works fine.
However, when I have another program, a React page,that uses the package, it fails to read the json file.
cat = require('test_package_cat')
cat.meow()
When I run index.js locally, if I console.log(__dirname), it gives me C://......../myProject.
However, when running the React app, console.log(__dirname) just prints "/" and when I try to print directories/files, it shows nothing.
How can I make the my npm package to read info.json file?
Edit: After more searching, I managed to get it working by doing:
let info = require('./info.json')
console.log(JSON.stringify(info))
but would still like to know how to do it using "readFile" way.
fs is only available in the Node runtime environment. It isn't available in a browser's JavaScript runtime environment. I'm surprised you haven't encountered an error to that effect.
I have confusion about access node_modules that can be used in JavaScript. for this does anyone can give an example to call modul.export contained in the folder node_module (after install packet with NPM - nodejs) ?
tree structure file :
folder ethereum any folder node_modules , file index.html (for call module.export) , package-lock.json , package.json
package.json file :
enter link description here
so this way, I've installed "npm install web3". Now, when I call a function from web3 like for example in a program like this :
var Web3=require('web3');
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/metamask"));
}
console.log(web3);
Then output errors like this :
enter image description here
The web3 package can either be installed through npm with npm install web3 or is exposed as a global web3 if you import it like:
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
It can either be run as a global exposed by the <script></script> tag or as a node package that needs to be bundled first.
Your error code require is not defined tells you that node is not running your code, but something else is consuming your code. Try to bundle your code to something the browser understands, or only use the global web3 to interact with the package.
Read more about bundles here: https://docs.npmjs.com/getting-started/packages
If I understand correctly, you are missing a big piece of the puzzle here.
You need to compile your code for the browser to be able to run it. Try reading up on this question
I am creating vue-cli project and everything works file, but when i try to install new module it show me error after install :
This dependency was not found:
* fs in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Index.vue, ./~/mp3-duration/index.js and 1 other
To install it, you can run: npm install --save fs
I tried multiple times to confirm but still an error, in the node_modules folder there is a library.
I am installing this module and using :
const musicdata = require('musicmetadata');
After add above code i am writing this :
getDuration(file) {
fs.createReadStream(file), (err, metadata) => {
if (err) throw err;
console.log(metadata)
}
}
But getting an error as I specified above, I want a single page website but want some node_modules to get some information, how do I include these modules?
Thanks
I would say this is because fs is a specifically for reading files in a Node application and you're running it in the browser. You could look into the FileReader API which helps read local files (and I would imagine your application's files). Worst case, someone has written an NPM package for it.
I'm in the process of re-writing my electron app with ES6, using Laravel Mix to compile the app JS and SASS. Now the main process loads up the render process fine. Once that happens my app.js loads up and that's where I have my issues. So I do:
import { remote } from 'electron';
Which causes this error in console:
Uncaught Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
Now i've tried reinstalling electron, even though electron works when the main process fires up to begin with. The line refers to this in the compiled js:
/* WEBPACK VAR INJECTION */(function(__dirname) {var fs = __webpack_require__(8)
var path = __webpack_require__(9)
var pathFile = path.join(__dirname, 'path.txt')
if (fs.existsSync(pathFile)) {
module.exports = path.join(__dirname, fs.readFileSync(pathFile, 'utf-8'))
} else {
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
}
I'm not really sure what's going on, any advice or information would be a great help!
Thanks
Edit: I've tried running it with --verbose:
/Library/Caches/com.apple.xbs/Sources/AppleGVA/AppleGVA-10.1.16/Sources/Slices/Driver/AVD_loader.cpp: failed to get a service for display 3
2017-06-13 16:10:42.383 Electron Helper[47106:766924] Couldn't set selectedTextBackgroundColor from default ()
Most probably source of problem is that path.txt doesn't exists.
path.txt is generated while installing electron from npm. If you are not seeing any error while installing electron that means, errors are getting suppressed.
Troubleshoot: Check if node_modules/electron/path.txt exist. If not, then you have got a problem.
Solution:
Note: If on Windows, use native CMD instead of Git Bash
Try to install electron manually after npm install by executing following script
cd node_modules/electron && node install.js
This may take up a while, since it is going to download electron's full package.