Cannot find module puppeteer-core/internal/puppeteer-core.js in node_modules\puppeteer\lib\cjs\puppeteer\puppeteer.js when using browserify

huangapple go评论108阅读模式
英文:

Cannot find module puppeteer-core/internal/puppeteer-core.js in node_modules\puppeteer\lib\cjs\puppeteer\puppeteer.js when using browserify

问题

以下是您的翻译内容:

  1. 我试图使用browserify更改我的脚本以在Chrome扩展中使用它但它一直出现这个错误我无法解决它
  2. [在此处输入图像描述](https://i.stack.imgur.com/242zk.jpg)
  3. 这是我的主要代码我只希望这段代码能在Web扩展环境中工作我尝试使用browserify但它仍然出现图片中的问题
  4. const puppeteer = require('puppeteer');
  5. const imdbScraper = require('easyimdbscraper');
  6. const fs = require('fs');
  7. // node popup.js
  8. async function getMovieId(movieTitle) {
  9. const browser = await puppeteer.launch({
  10. headless: true,
  11. userDataDir: "./tmp"
  12. });
  13. const page = await browser.newPage();
  14. await page.goto(`https://www.google.com/search?q=${movieTitle}`);
  15. const Handles = await page.$('.yuRUbf');
  16. const anchorElement = await Handles.$('a');
  17. const title = await page.evaluate(el => el.href, anchorElement)
  18. const string = title;
  19. const regex = /tt(\d+)/;
  20. const match = string.match(regex);
  21. let imdbId = match ? match[1] : null;
  22. imdbId = "tt" + imdbId;
  23. await browser.close();
  24. return imdbId;
  25. };
  26. async function getInfoAboutMovie(movieId) {
  27. var info = await imdbScraper.getInfoByID(movieId)
  28. var infoJSON = JSON.stringify(info, null, 2); // JSON formatina dönüştürme ve düzgün bir şekilde formatlama
  29. fs.writeFile('movie_info.json', infoJSON, 'utf8', () => {
  30. console.log('Dosya başarıyla yazıldı: movie_info.json');
  31. });
  32. }
  33. async function changeData() {
  34. fs.readFile('./movie_info.json', 'utf8', (err, data) => {
  35. if (err) {
  36. console.error('Dosya okunamadı:', err);
  37. return;
  38. }
  39. const info = JSON.parse(data);
  40. const imgElement = document.querySelector(".resim");
  41. imgElement.src = info.poster;
  42. console.log("hello there");
  43. });
  44. }
  45. async function main() {
  46. let movieTitle = 'spiderman across';
  47. movieTitle = movieTitle + " imdb";
  48. var movieId = await getMovieId(movieTitle);
  49. await getInfoAboutMovie(movieId);
  50. await changeData();
  51. }
  52. main();

希望这有助于您的项目。如果您有任何其他疑问,请随时提出。

英文:

I'm trying to change my script with browserify to use it in chrome extension, but it keeps giving this error and I couldn't solve it.
enter image description here

this is my main code, all I want is for this code to work in the web extension environment, I tried using browserify for this, but it continues to give the problem in the picture.

  1. const puppeteer = require('puppeteer');
  2. const imdbScraper = require('easyimdbscraper')
  3. const fs = require('fs');
  4. // node popup.js
  5. async function getMovieId (movieTitle) {
  6. const browser = await puppeteer.launch({
  7. headless: true,
  8. userDataDir: "./tmp"
  9. });
  10. const page = await browser.newPage();
  11. await page.goto(`https://www.google.com/search?q=${movieTitle}`);
  12. const Handles = await page.$('.yuRUbf');
  13. const anchorElement = await Handles.$('a');
  14. const title = await page.evaluate(el => el.href,anchorElement)
  15. const string = title;
  16. const regex = /tt(\d+)/;
  17. const match = string.match(regex);
  18. let imdbId = match ? match[1] : null;
  19. imdbId = "tt" + imdbId;
  20. await browser.close();
  21. return imdbId;
  22. };
  23. async function getInfoAboutMovie (movieId) {
  24. var info = await imdbScraper.getInfoByID(movieId)
  25. var infoJSON = JSON.stringify(info, null, 2); // JSON formatina dönüştürme ve düzgün bir şekilde formatlama
  26. fs.writeFile('movie_info.json', infoJSON, 'utf8', () => {
  27. console.log('Dosya başariyla yazildi: movie_info.json');
  28. });
  29. }
  30. async function changeData() {
  31. fs.readFile('./movie_info.json', 'utf8', (err, data) => {
  32. if (err) {
  33. console.error('Dosya okunamadı:', err);
  34. return;
  35. }
  36. const info = JSON.parse(data);
  37. const imgElement = document.querySelector(".resim");
  38. imgElement.src = info.poster;
  39. console.log("hello there");
  40. });
  41. }
  42. async function main() {
  43. let movieTitle = 'spiderman across';
  44. movieTitle = movieTitle + " imdb";
  45. var movieId = await getMovieId(movieTitle);
  46. await getInfoAboutMovie(movieId);
  47. await changeData();
  48. }
  49. main();

答案1

得分: 1

npm i puppeteer@18.1.0

英文:

When I put puppeteer to the following version and tried it, the problem was solved for the moment:

  1. npm i puppeteer@18.1.0

huangapple
  • 本文由 发表于 2023年7月3日 20:06:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76604577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定