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

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

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

问题

以下是您的翻译内容:

我试图使用browserify更改我的脚本以在Chrome扩展中使用它但它一直出现这个错误我无法解决它
[在此处输入图像描述](https://i.stack.imgur.com/242zk.jpg)

这是我的主要代码我只希望这段代码能在Web扩展环境中工作我尝试使用browserify但它仍然出现图片中的问题

const puppeteer = require('puppeteer');
const imdbScraper = require('easyimdbscraper');
const fs = require('fs');

// node popup.js

async function getMovieId(movieTitle) {

  const browser = await puppeteer.launch({
    headless: true,
    userDataDir: "./tmp"
  });

  const page = await browser.newPage();
  await page.goto(`https://www.google.com/search?q=${movieTitle}`);
  
  const Handles = await page.$('.yuRUbf');
  const anchorElement = await Handles.$('a');
  const title = await page.evaluate(el => el.href, anchorElement)
  
  const string = title;
  const regex = /tt(\d+)/;
  const match = string.match(regex);
  let imdbId = match ? match[1] : null;
  imdbId = "tt" + imdbId;

  await browser.close();
  
  return imdbId;
};



async function getInfoAboutMovie(movieId) {
  var info = await imdbScraper.getInfoByID(movieId)

  var infoJSON = JSON.stringify(info, null, 2); // JSON formatina dönüştürme ve düzgün bir şekilde formatlama
  
  fs.writeFile('movie_info.json', infoJSON, 'utf8', () => {
    console.log('Dosya başarıyla yazıldı: movie_info.json');
  });

 
}

async function changeData() {
  fs.readFile('./movie_info.json', 'utf8', (err, data) => {
    if (err) {
      console.error('Dosya okunamadı:', err);
      return;
    }
    const info = JSON.parse(data);

    const imgElement = document.querySelector(".resim");
    imgElement.src = info.poster;
    console.log("hello there");
  });
}


async function main() {
  let movieTitle = 'spiderman across';
  movieTitle = movieTitle + " imdb";
  var movieId = await getMovieId(movieTitle);
  await getInfoAboutMovie(movieId);
  await changeData();
}

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.

const puppeteer = require('puppeteer');
const imdbScraper = require('easyimdbscraper')
const fs = require('fs');
// node popup.js
async function getMovieId (movieTitle) {
const browser = await puppeteer.launch({
headless: true,
userDataDir: "./tmp"
});
const page = await browser.newPage();
await page.goto(`https://www.google.com/search?q=${movieTitle}`);
const Handles = await page.$('.yuRUbf');
const anchorElement = await Handles.$('a');
const title = await page.evaluate(el => el.href,anchorElement)
const string = title;
const regex = /tt(\d+)/;
const match = string.match(regex);
let imdbId = match ? match[1] : null;
imdbId = "tt" + imdbId;
await browser.close();
return imdbId;
};
async function getInfoAboutMovie (movieId) {
var info = await imdbScraper.getInfoByID(movieId)
var infoJSON = JSON.stringify(info, null, 2); // JSON formatina dönüştürme ve düzgün bir şekilde formatlama
fs.writeFile('movie_info.json', infoJSON, 'utf8', () => {
console.log('Dosya başariyla yazildi: movie_info.json');
});
}
async function changeData() {
fs.readFile('./movie_info.json', 'utf8', (err, data) => {
if (err) {
console.error('Dosya okunamadı:', err);
return;
}
const info = JSON.parse(data);
const imgElement = document.querySelector(".resim");
imgElement.src = info.poster;
console.log("hello there");
});
}
async function main() {
let movieTitle = 'spiderman across';
movieTitle = movieTitle + " imdb";
var movieId = await getMovieId(movieTitle);
await getInfoAboutMovie(movieId);
await changeData();
}
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:

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:

确定