Answer the question
In order to leave comments, you need to log in
Why doesn't the script compiled by webpack work?
Good day.
For example, there is a small script that works if you run it directly from the project where it is being developed.
It is built via npm run build does not work giving an error.
Script code
const puppeteer = require('puppeteer');
const browserURL = "http://127.0.0.1:21223"
const url = "https://ya.ru"
const start = async () => {
const browser = await puppeteer.connect({
browserURL,
defaultViewport: {
width: 1920, height: 1080
},
})
const page = await browser.newPage();
await await page.goto(url)
}
start()
node .\src\r.js
then the browser opens ya.ru. (node:3852) UnhandledPromiseRejectionWarning: TypeError: Failed to fetch browser webSocket URL from http://127.0.0.1:21223/json/version: fetch is not a function
at getWSEndpoint (d:\JS\r.js:8494:30)
at async Object.connectToBrowser (d:\JS\r.js:8481:31)
at async start (d:\JS\r.js:33806:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3852) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3852) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
const rConfig = {
entry: './src/r.js',
mode: "production",
target: "node",
optimization: {
minimize: false
},
output: {
filename: "r.js",
path: 'D:\\JS'
}
}
module.exports = [rConfig]
{
"scripts": {
"build": "webpack"
},
"dependencies": {
"puppeteer": "^10.2.0"
},
"devDependencies": {
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question