[英]fs.readFileSync is not a function?
我正在嘗試讓機器人運行客戶端並控制第三方頁面,但出現此錯誤我正在使用瀏覽器。
Uncaught TypeError: fs.readFileSync is not a function,
這是我的代碼
global.apostar = function() {
var fs = require('fs')//require
var src = fs.readFileSync(__dirname + '/file.txt')
const nodeExternals = require('webpack-node-externals')
module.exports = {
entry: './bundle.js',
target: 'node',
externals: [nodeExternals()],
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js'
}
}
const auxiliar = require(electron)
const{Builder, By, Key, util} = require('selenium-webdriver')
async function example() {//construir o chrome webdriver
let driver = await new Builder().forBrowser("firefox").build()
await driver.get("http://google.com")
await driver.findElement(By.name("q")).sendKeys("Selenium",Key.RETURN)
}
example()
//call function
}
您不能在瀏覽器中使用“fs”,因為它是 Node.js 特定庫,可在操作系統級別啟用文件系統操作。 瀏覽器不支持這些低級 API,因此您只能在 Node.js 中使用它。
Google 目前正在開發基於瀏覽器的文件系統 api ,也許這會有所幫助。
順便說一句,Selenium 也將不起作用,因為它會再次使用操作系統級別的 API 生成另一個瀏覽器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.